2017-04-26 66 views
0

請看下面的input()調用是如何處理的。我究竟做錯了什麼?python vs jython - input and NameError:name''is not defined

> 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

回答

1

Jython的版本是Python 2.7版兼容,而使用Python調用是蟒蛇3.x的這與Jython實際上無關。

與v3相比,python v2中的輸入調用執行不同的操作。

這在this頁面記錄得相當好。

+0

感謝的確如此。 –