简体   繁体   中英

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

This confuses me because, shouldn't this take input and store it in a new variable "wpn" where once it was stored in "input"? When I change wpn to input it works, but not if I ask it to take user input...

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.

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:

user_input = input()

Now it won't overwrite the function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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