y2k*_*y2k 125 python string format typeerror
这是输出.这些是utf-8字符串我相信......其中一些可以是NoneType但它会立即失败,在那之前......
instr = "'%s', '%s', '%d', '%s', '%s', '%s', '%s'" % softname, procversion, int(percent), exe, description, company, procurl
Run Code Online (Sandbox Code Playgroud)
TypeError:格式字符串的参数不足
7虽然7?
And*_*ark 226
您需要将格式参数放入元组(添加括号):
instr = "'%s', '%s', '%d', '%s', '%s', '%s', '%s'" % (softname, procversion, int(percent), exe, description, company, procurl)
Run Code Online (Sandbox Code Playgroud)
您目前拥有的内容相当于以下内容:
intstr = ("'%s', '%s', '%d', '%s', '%s', '%s', '%s'" % softname), procversion, int(percent), exe, description, company, procurl
Run Code Online (Sandbox Code Playgroud)
例:
>>> "%s %s" % 'hello', 'world'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: not enough arguments for format string
>>> "%s %s" % ('hello', 'world')
'hello world'
Run Code Online (Sandbox Code Playgroud)
Sim*_*ser 155
请注意,%格式化字符串的语法已过时.如果您的Python版本支持它,您应该写:
instr = "'{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}'".format(softname, procversion, int(percent), exe, description, company, procurl)
Run Code Online (Sandbox Code Playgroud)
这也解决了您碰巧遇到的错误.
小智 13
在格式字符串中使用%作为百分比字符时出现相同的错误.解决方法是将%%加倍.
| 归档时间: |
|
| 查看次数: |
215844 次 |
| 最近记录: |