2
我在python交互模式下嘗試編碼像波紋管時得到了語法錯誤反應。Python交互模式下的錯誤?
>>> while True:
... reply = raw_input('enter text:')
... if reply == 'stop':
... break
... print reply
... print 'bye'
File "<stdin>", line 6
print reply
^
SyntaxError: invalid syntax
>>>
但它保存爲腳本時正常執行。
~ $cat test.py
#!/usr/bin/env python
# encoding=utf8
while True:
reply = raw_input('enter text:')
if reply == 'stop':
break
print reply
print 'bye'
~ $python test.py
enter text:19
19
enter text:456789
456789
enter text:$%^&*(
$%^&*(
enter text:TGHJKLO:P
TGHJKLO:P
enter text:#$%^&*()_
#$%^&*()_
enter text:stop
bye
它是一個錯誤?或者我應該知道的有關python交互模式的其他任何事情?
~ $python -V
Python 2.6.6
[過了一會兒做蟒紋]的可能重複(http://stackoverflow.com/questions/5751135/python-print-done-after-while) – 2011-04-24 00:47:38