简体   繁体   中英

Python raw_input(“”) error

I am writing a simple commandline script that uses raw_input, but it doesn't seem to work.

This code:

print "Hello!"
raw_input("")

Produces this error:

Traceback (most recent call last):
 File "<pyshell#6>", line 1, in <module>
raw_input("")
TypeError: 'str' object is not callable

I have never encountered this error before, and couldn't find anything on Google. I am using Python 2.6 on Windows 7.

Works fine as presented, eg in an interpreter prompt in any Python 2 version:

>>> print "Hello!"
Hello!
>>> raw_input("")
bah
'bah'
>>> 

where bah is what I typed after the code you gave in response to the empty-prompt;-).

The only explanation for the error you mention is that you've performed other code before this, which included binding identifier raw_input to a string.

It appears you are using something called pyshell . There is likely a bug there in that shell itself. Try just using vanilla bash.

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