【问题标题】:See if Python2 code will compile in Python3看看 Python2 代码是否会在 Python3 中编译
【发布时间】:2015-10-21 19:19:18
【问题描述】:

我的电脑上安装了 Python2.7。有没有办法查看我拥有的 .py 代码是否可以在没有安装 Python3 的情况下在 Python3 中编译?

【问题讨论】:

    标签: python python-2.7 python-3.x


    【解决方案1】:

    你可以使用这个程序:https://docs.python.org/2/library/2to3.html

    它将您的代码形式 2 转换为 3,或为您提供有关需要更改的信息。

    【讨论】:

      【解决方案2】:

      在不了解您的代码或操作系统的情况下,很难说什么是最好的。如果静态分析是您想要的方式,我建议您查看一下,看看是否有任何差异:

      https://docs.python.org/3/whatsnew/3.0.html#common-stumbling-blocks

      顺便说一句,如果你改变主意,Python 2 和 3 可以同时安装在同一台机器上,而不需要太多的努力。

      如果您运行的是 Linux:Running both python 2.6 and 3.1 on the same machine

      如果您运行的是 Windows:How to install both Python 2.x and Python 3.x in Windows 7

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-05-12
        • 2013-07-13
        • 1970-01-01
        • 2010-10-02
        • 2010-12-02
        相关资源
        最近更新 更多