根据您的错误消息“NameError: global name 'next' is not defined”和 update_project python 脚本的 1.9.0 版本的内容,我假设您运行的 python 版本低于 2.6。下一个函数是 Python 2.6 ( http://docs.python.org/2/library/functions.html#next ) 中引入的 python 内置函数。这是升级脚本中的一个已知错误,因为它应该与 Python 2.4 和 Python 2.6 兼容(分别是 CentOS 5 和 6 中的默认 python 安装)。要解决此问题,您可以修改 $OSSIEHOME/bin/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”函数。
最后,您需要用对新实现的 next 函数的调用替换对“safe_next”的两次调用,并添加空字符串的第二个参数 ''
为清楚起见,update_project 与这些更改的差异如下:
@@ -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