2011-02-04 41 views
1

錯誤:Python中沒有足夠的參數錯誤,我應該怎麼做才能解決這個問題?

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

我將如何解決這個問題:這是造成錯誤

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 

代碼行?

+0

你不認真,對嗎?你無法計算`%`的數量? – 2011-02-04 23:45:53

回答

6

您需要提供另一個地方放置第二個字符串。從Python文檔:

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).

因此,對於你比如你要:

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

假設當然,這self.level是一個字符串。如果它是一些其他值類型,那麼你想交換適當的字符串格式化值。 (整數的%d等)。

+0

感謝您的回答,它的工作原理! – 2011-02-04 23:03:12

相關問題