Python TypeError:格式字符串没有足够的参数 [英] Python TypeError: not enough arguments for format string

查看:424
本文介绍了Python TypeError:格式字符串没有足够的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是输出。这些是utf-8字符串,我相信...其中一些可以是NoneType,但它会立即失败,之前的那些...

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

TypeError:format string

的参数不足b
$ b

它的7是7吗?

解决方案

注意格式化字符串的%语法已经过时。如果您的Python版本支持,您应该写:

  instr ={0},{1} ,{2},{3},{4},{5},{6}格式(软名称,procversion,int(百分比),exe,description,company,procurl )

这也解决了您遇到的错误。


Here's the output. These are utf-8 strings I believe... some of these can be NoneType but it fails immediately, before ones like that...

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

TypeError: not enough arguments for format string

Its 7 for 7 though?

解决方案

Note that the % syntax for formatting strings is becoming outdated. If your version of Python supports it, you should write:

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

This also fixes the error that you happened to have.

这篇关于Python TypeError:格式字符串没有足够的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆