Convert python 2 code to 3 in PyCharm

前端 未结 5 1822
-上瘾入骨i
-上瘾入骨i 2020-12-08 04:48

I have a large ML project in python 2 code and I just started using PyCharm as an IDE. I\'m currently using WinPython 3.4 and I\'d preferably like to do everything in python

5条回答
  •  情书的邮戳
    2020-12-08 05:16

    Before anything I would save a backup copy of your Python 2 file first.

    You can then try to convert the code using the "2to3" Automated Python 2 to 3 code translation tool which is built into Python via the Standard Library. Details on usage can be found here: https://docs.python.org/2/library/2to3.html#

    You also have the choice between two tools to port your code automatically: Modernize and Futurize. Check them out below.

    Modernize --> https://python-modernize.readthedocs.io/en/latest/

    Futurize --> http://python-future.org/automatic_conversion.html

    In terms of Pycharm, I have not seen / don't know of any specialized tool within the IDE that converts code from Python 2 to Python 3. I'd stick to the 3 tools above.

    Good luck!

提交回复
热议问题