【问题标题】:How to use 2to3 tool in windows?如何在 Windows 中使用 2to3 工具?
【发布时间】:2012-06-17 11:42:06
【问题描述】:

我尝试通过运行命令使用 2to3 工具修改 sintax

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

得到输出

当打开 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?

【问题讨论】:

标签: python python-2to3


【解决方案1】:

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

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

请参阅2to3.py documentation

【讨论】:

  • 我只是在字母 C: 上得到了无效语法:
  • @Ifyoudonotknow-justGIS 什么意思?
【解决方案2】:

作为已接受答案的补充,

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

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

之后就可以使用了

2to3 -w neo4j.py

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-30
    • 2011-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多