请查看下面的 input() 调用是如何处理的。我做错了什么?
> python
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> currentQryAlias=input('Please enter alias for the query: ')
Please enter alias for the query: recospace
>>> print ('What is the value of currentQryAlias? ', currentQryAlias)
What is the value of currentQryAlias? recospace
>>> print ('type of currentQryAlias: ',type(currentQryAlias))
type of currentQryAlias: <class 'str'>
>>> ^Z
cd C:\Python\jython2.7.0
> .\bin\jython
Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_31
Type "help", "copyright", "credits" or "license" for more information.
>>> currentQryAlias=input('Please enter alias for the query: ')
Please enter alias for the query: recospace
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
NameError: name 'recospace' is not defined
>>>
基本上在 jython 下,如果我需要输入一个字符串,我必须将它用引号引起来。如果我在 jython 下的调用中输入“recospace”,同样可以正常工作。
> .\bin\jython
Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_31
Type "help", "copyright", "credits" or "license" for more information.
>>> currentQryAlias=input('Please enter alias for the query: ')
Please enter alias for the query: 'recospace'
>>>
谢谢, DP
Jython 版本与 python 2.7 兼容,而您实际的 python 调用是 python 3.x。这实际上与 Jython 无关。
与 v3 相比,输入调用在 python v2 中执行不同的操作。
这在this页面上有很好的记录。