开发者

Not enough arguments error in Python, what should I do to fix this?

开发者 https://www.devze.com 2023-02-08 10:28 出处:网络
Error: Traceback (most recent call last): File \"C:\\Python26\\Lib\\idlelib\\full_rpg.py\", line 145, in <module>

Error:

Traceback (most recent call last):
  File "C:\Python26\Lib\idlelib\full_rpg.py", line 145, in <module>
    Commands[c](p)
  File "C:\Python26\Lib\idlelib\full_rpg.py", line 57, in status
    print "%s's Level:" % (self.name, self.level)
TypeError: not all arguments converted during string formatting

Code line which is causing the error:

print "%s's Level:" % (self.name, self.level)

How would I fix this?开发者_JAVA百科


You need to provide another place to put the second string. From the python docs:

If format requires a single argument, values may be a single non-tuple object. [4] Otherwise, values must be a tuple with exactly the number of items specified by the format string, or a single mapping object (for example, a dictionary).

So for your example you want:

"%s's Level: %s" % (self.name, self.level)

Assuming of course that self.level is a string. If it's some other value type then you want to swap in the appropriate string formatting value. (%d for Integers, etc).

0

精彩评论

暂无评论...
验证码 换一张
取 消