将代码从Python 2.x转换为3.x.

Rem*_*mko 1 python python-3.x

这是我上一个问题的后续内容,我正在使用Senthil Kumaran建议的2to3工具

它似乎运作良好,但它没有拿起这部分:

raise LexError,("%s:%d: Rule '%s' returned an unknown token type '%s'" % (
    func.func_code.co_filename, func.func_code.co_firstlineno,
    func.__name__, newtok.type),lexdata[lexpos:])
Run Code Online (Sandbox Code Playgroud)

这在3.2中应该是什么样的?

编辑:从下面的答案的变化是好的,2to3现在似乎工作正常.在setup.py构建中,我现在得到以下错误,请参阅我的新问题.

Sve*_*ach 9

func_code函数的属性已重命名为__code__,请尝试

func.__code__.co_filename, func.__code__.co_firstlineno,
Run Code Online (Sandbox Code Playgroud)

作为代码段的第二行.