如何在Windows中使用2to3工具?

时间:2012-06-17 11:42:06

标签: python python-2to3

我试图通过运行命令

使用2to3工具修改sintax
python C:\Python32\Tools\scripts\2to3.py neo4j.py

并获得输出

enter image description here

打开neo4j.py但是我注意到没有任何改变。下面是应该进行更改(符合输出)的代码块:

try:
    import json
except ImportError:
    import simplejson as json
try:
    from urllib.parse import quote
except ImportError:
    from urllib import quote
try:
    from . import rest, batch, cypher
except ImportError:
    import rest, batch, cypher
except ValueError:
    import rest, batch, cypher

import logging
logger = logging.getLogger(__name__)

是否有人知道如何正确使用2to3工具以便将代码移植/更改为v3.2?

2 个答案:

答案 0 :(得分:48)

您必须使用-w标志来实际编写更改:

python C:\Python32\Tools\scripts\2to3.py -w neo4j.py

请参阅2to3.py documentation

答案 1 :(得分:3)

作为已接受答案的补充,

将此行复制到C:\python32\Scripts\2to3.bat

@python %~dp0..\tools\scripts\2to3.py %*

之后你就可以使用

2to3 -w neo4j.py