繁体   English   中英

TypeError:在PyDev for Eclipse中使用input()时,无法调用'str'对象

[英]TypeError: 'str' object is not callable when using input() in PyDev for Eclipse

类似的答案

我第一次在Eclipse的PyDev中制作了一个基本的文字冒险游戏,当我尝试让用户多次输入时,遇到上述错误。 以下是我使用的生成错误的代码:

print("Input a name for your character.")    
input = input()    
player = Character(input)

我已经定义了Character类,并且将str作为其参数。 设置器在下面。

player.setName(input)    
print("\nWelcome, "+input+"!\nChoose a weapon from the list below.")    
print("\nfists\ndagger\nspear\naxe\nshortsword\nlongsword\nmace")    
wpn = input()

我在用wpn = input()的行上收到TypeError ,说'str' object is not callable

这使我感到困惑,因为这不应该接受输入并将其存储在新的变量“ wpn”中,一旦存储在“ input”中吗? 当我将wpn更改为输入时,它可以工作,但是如果我要它接受用户输入,则不行...

我每次都希望有唯一的用户输入,但是由于这个错误,我不确定如何完成该输入。

您已将输入更改为字符串。 它不再是原始输入函数的功能。 给输入的值返回一个不同的名称:

user_input = input()

这将保持input功能不变。

它不起作用,因为您的变量input将覆盖实际的input函数,因此解决此问题的最佳方法是重命名变量,请尝试以下操作:

user_input = input()

现在它不会覆盖该功能

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM