这是输出。我相信这些是utf-8字符串...其中一些可以是NoneType,但它会立即失败,在这样的之前...
instr = "'%s', '%s', '%d', '%s', '%s', '%s', '%s'" % softname, procversion, int(percent), exe, description, company, procurl
TypeError:格式字符串的参数不足
是7个人中的7个吗?
发布于 2012-06-22 04:36:18
请注意,用于格式化字符串的%
语法正在过时。如果您的Python版本支持它,您应该这样写:
instr = "'{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}'".format(softname, procversion, int(percent), exe, description, company, procurl)
这也修复了你碰巧遇到的错误。
发布于 2012-06-22 04:27:31
您需要将格式参数放入一个元组(添加圆括号):
instr = "'%s', '%s', '%d', '%s', '%s', '%s', '%s'" % (softname, procversion, int(percent), exe, description, company, procurl)
您当前拥有的内容相当于以下内容:
intstr = ("'%s', '%s', '%d', '%s', '%s', '%s', '%s'" % softname), procversion, int(percent), exe, description, company, procurl
示例:
>>> "%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'
发布于 2017-07-07 02:33:01
当在格式化字符串中使用%
作为百分号字符时,我得到了相同的错误。这个问题的解决方案是将%%
加倍。
https://stackoverflow.com/questions/11146190
复制相似问题