在PyCharm中将python 2代码转换为3 [英] Convert python 2 code to 3 in PyCharm

查看:1023
本文介绍了在PyCharm中将python 2代码转换为3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在python 2代码中有一个大的ML项目,我刚开始使用PyCharm作为IDE。我目前使用WinPython 3.4,我最好喜欢在python 3中做所有事情,而不是继续使用legacy 2.当我从git中克隆项目时,出现了pycharm中的一个弹出窗口,这是将代码转换为3从2,但我没有真正考虑它并退出它。我如何转换它?

解决方案

我使用2to3工具在 Pycharm IDE中找到了将文件从v2转换为v3的方法。



我在Windows环境中应用于pycharm comunity edition v 2016.2.3。




  • 在状态栏中单击终端
    现在,您在shell命令中,位于项目的根目录中。
  • 转换myfile.py):

    2to3 myfile.py -w



该工具修改文件的代码,并且您的IDE会与更改一起反映。



要修改文件夹中的所有文件,请键入命令

  2to3。 -w 

选项-w实际编写更改。
详情请见:

  2to3 -h 


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 3 instead of continue using legacy 2. When I cloned the project from git a popup in pycharm came up that was something along the lines of converting the code to 3 from 2 but I didn`t really think about it and exited it. How do I convert it?

解决方案

I found a way in Pycharm IDE to convert file from v2 to v3 using 2to3 tool.

I applied in pycharm comunity edition v 2016.2.3 in windows environment.

  • click terminal in status bar Now, you are in shell command, in the root of your project.
  • type the command (to convert myfile.py):

    2to3 myfile.py -w

The tool modifies the code of the file, and your IDE is reflected with the changes.

To modify all your files in the folder, type the command

2to3 . -w

The option -w to actually write the changes. For more details write:

  2to3 -h

这篇关于在PyCharm中将python 2代码转换为3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆