根據您的錯誤消息「NameError:global name'next'未定義」以及1.9.0版本的update_project python腳本的內容,我假設您正在運行的python版本低於2.6。下一個函數是Python 2.6中引入的python內建函數(http://docs.python.org/2/library/functions.html#next)。這是升級腳本中的一個已知錯誤,因爲它應該與Python 2.4以及Python 2.6兼容(分別爲CentOS 5和6中的默認python安裝)。爲了解決這個問題,你可以修改位於$ OSSIEHOME /斌/ update_project的update_project腳本並定義以下功能:
if not hasattr(__builtins__, 'next'):
# Python 2.4 does not have a free-standing next() function
def next(iterator, default):
"""
Backwards compatibility next() equivalent for Python 2.4.
"""
try:
return iterator.next()
except StopIteration:
return default
然後您應該刪除以前定義的「safe_next」功能。
最後,你需要給新執行下一個功能,並添加空字符串「」
爲了清楚起見,update_project的這些改變的差異的第二個參數調用替換兩次調用「safe_next」如下:
@@ -46,16 +46,16 @@ Options:
_bulkio_re = re.compile('BULKIO_data[A-Za-z]+_In_i')
-def safe_next(item):
- """
- Returns the next value of the iterator, or an empty string if the end of
- iteration has been reached. Allows string processing to gracefully handle
- the end of a line without explicit catch statements.
- """
- try:
- return next(item)
- except StopIteration:
- return ''
+if not hasattr(__builtins__, 'next'):
+ # Python 2.4 does not have a free-standing next() function
+ def next(iterator, default):
+ """
+ Backwards compatibility next() equivalent for Python 2.4.
+ """
+ try:
+ return iterator.next()
+ except StopIteration:
+ return default
def strip_comments(source):
"""
@@ -75,7 +75,7 @@ def strip_comments(source):
# Look for end comment token; if the end of the line is reached
# ch will be an empty string
while ch == '*':
- ch = safe_next(chars)
+ ch = next(chars, '')
if ch == '/':
inComment = False
break
@@ -83,7 +83,7 @@ def strip_comments(source):
if ch == '/':
# Read the next character to see if it matches a comment token
# (if it does not, both characters will be added to the output)
- ch += safe_next(chars)
+ ch += next(chars, '')
if ch == '/*':
# Comment, start discarding
inComment = True
我發現update_project python腳本與Python版本2.4.3不兼容。看來這個版本的python不能識別迭代器上的下一個命令。在嘗試更高版本的python時,升級腳本按預期工作。 –
我使用的是Python 2.4.3版本附帶的CentOS 5.3。 –