query = "SELECT * FROM devices WHERE devices.`id` LIKE '%{}%'".format("f2333") datas = cur.query(query) 报错: query = query % tuple([db.literal(item) for item in args]) TypeError: not enough arguments for format string 传入query语句拼接出来为 SEL…
python3和python2的写法不一样具体如下: python3: with open(r'd:\ssss.txt','w',encoding='utf-8') as f: f.write(u'中文') python2中open方法是没有encoding这个参数的,如果像python3一样的写法会报异常:TypeError: 'encoding' is an invalid keyword argument for this function python2中需要加上: import sys…
#### 字符串格式化. # %s 代替任何的元素 (数字,字符串,列表··) print('I live %s crty' %'my') print('I live %s crty' %'[6,8,9]') I live my crty I live [6,8,9] crty # %s -- %( ) 可以代替多个元素 print('I live %s crty,prefer live %s country' %('your','my')) I live your crty,prefer li…
python3和python2的写法不一样具体如下: python3: with open(r'd:\ssss.txt','w',encoding='utf-8') as f: f.write(u'中文') python2中open方法是没有encoding这个参数的,如果像python3一样的写法会报异常:TypeError: 'encoding' is an invalid keyword argument for this function python2中需要加上: import sys…
字符串前加 f(重点!敲黑板!) 作用:相当于 format() 函数 name = "帅哥" age = 12 print(f"my name is {name},age is {age}") 执行结果 my name is 帅哥,age is 12 字符串前加 r r"" 的作用是:去除转义字符 场景:想复制某个文件夹的目录,假设是 F:\Python_Easy\n4\test.py 当你不用 r"" ,你有三种写法 p…
# %s可以接收一切 %d只能接收数字 msg = 'i am %s my hobby is %s' %('lhf','alex') print msg msg2 = 'i am %s my hobby is %d' %('lhf',1) print msg2 #打印浮点数 tpl ="percent %.2f" %99.976 #截取几位 print tpl tpl2 = "i am %(name)s age %(age)d" %{"name"…