简体   繁体   English

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

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

A similar answer 类似的答案

I'm making a basic text adventure game for the first time in PyDev in Eclipse and when I try to have the user give input more than once I get the above error. 我第一次在Eclipse的PyDev中制作了一个基本的文字冒险游戏,当我尝试让用户多次输入时,遇到上述错误。 Below is the code I used that generated the error: 以下是我使用的生成错误的代码:

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

I already have the class Character defined and it takes a str as its argument. 我已经定义了Character类,并且将str作为其参数。 The setter is below. 设置器在下面。

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

I get a TypeError on the line with wpn = input() " saying 'str' object is not callable . 我在用wpn = input()的行上收到TypeError ,说'str' object is not callable

This confuses me because, shouldn't this take input and store it in a new variable "wpn" where once it was stored in "input"? 这使我感到困惑,因为这不应该接受输入并将其存储在新的变量“ wpn”中,一旦存储在“ input”中吗? When I change wpn to input it works, but not if I ask it to take user input... 当我将wpn更改为输入时,它可以工作,但是如果我要它接受用户输入,则不行...

I want unique user inputs each time, but I'm not sure how to accomplish that given this error. 我每次都希望有唯一的用户输入,但是由于这个错误,我不确定如何完成该输入。

You've changed input to be a string. 您已将输入更改为字符串。 It's no longer what the original input function does. 它不再是原始输入函数的功能。 Give the value that input returns a different name: 给输入的值返回一个不同的名称:

user_input = input()

This will keep the input function as it is. 这将保持input功能不变。

It is not working because your variable input is overwriting the real input function, so the best way to solve this is to rename the variable, try this: 它不起作用,因为您的变量input将覆盖实际的input函数,因此解决此问题的最佳方法是重命名变量,请尝试以下操作:

user_input = input()

Now it won't overwrite the function 现在它不会覆盖该功能

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

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