解决python打印%号和%format输出问题

>>> print('%s' %'1')
1
>>> print('%s%' %'1')
Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    print('%s%' %'1')
ValueError: incomplete format

  

解决:用%%代替%

>>> print('%%[%s,%.2f]%%' %('1',0.986))
%[1,0.99]%

sql使用:

  sql = ''' SELECT t. * FROM a t WHERE a.id=:id and data_time = '%s' 
              and file like 'ss_%s_%%[%s]%%' ''' %('20190101','abc','z.txt')

  

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 1970-01-01
  • 2022-12-23
  • 2021-08-15
  • 2022-01-15
  • 2022-12-23
  • 2021-08-29
猜你喜欢
  • 2022-01-22
  • 2021-05-18
  • 2022-02-15
  • 2022-01-07
  • 2022-03-08
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案