我正在重构一些 python2 代码并使用 2to3 模块将其更改为 python3。我收到以下解析错误:
RefactoringTool: There was 1 error:
RefactoringTool: Can't parse ./helpers/repo.py: ParseError: bad input: type=22, value='=', context=(' ', (45, 25))
这是产生错误的代码:
except ImportError as error_msg: # pragma: no cover
print(' ', file = sys.stderr) # this is a line that yields error
print("Could not locate modifyrepo.py", file=sys.stderr)
print("That is odd... should be with createrepo", file=sys.stderr)
raise ImportError(error_msg)
我不知道出了什么问题。你能帮忙吗?
问题是您尝试转换的代码不是有效的 Python 2 代码。
使用 Python 2 运行代码时,您将收到以下错误:
File "repo.py", line 5
print(' ', file = sys.stderr) # this is a line that yields error
^
SyntaxError: invalid syntax
看起来这段代码已经是 Python 3 代码了。使用 Python 3 您的代码不会产生语法错误。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)