Python TypeError:格式字符串的参数不足(Python TypeError: not enough arguments for format string)

系统教程 行业动态 更新时间:2024-06-14 17:04:03
Python TypeError:格式字符串的参数不足(Python TypeError: not enough arguments for format string)

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

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

TypeError:格式字符串的参数不足

其7为7虽然?

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?

最满意答案

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

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

这也修复了您遇到的错误。

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.

更多推荐

本文发布于:2023-04-24 21:01:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/5c8d323bbea92072f491d4e73cca843f.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   参数   格式   TypeError   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!