150

これが出力です。これらは私が信じているutf-8文字列です...これらのいくつかはNoneTypeである可能性がありますが、そのようなものの前にすぐに失敗します...

instr = "'%s', '%s', '%d', '%s', '%s', '%s', '%s'" % softname, procversion, int(percent), exe, description, company, procurl

TypeError: フォーマット文字列に十分な引数がありません

でも7対7?

4

4 に答える 4

267

format引数をタプルに入れる必要があります(括弧を追加します)。

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'
于 2012-06-21T20:27:31.243 に答える
188

%文字列をフォーマットするための構文は時代遅れになっていることに注意してください。お使いの Python のバージョンがサポートしている場合は、次のように記述します。

instr = "'{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}'".format(softname, procversion, int(percent), exe, description, company, procurl)

これにより、たまたま発生したエラーも修正されます。

于 2012-06-21T20:36:18.223 に答える