python2转python3代码_在PyCharm中将python 2代码转换为3

1586010002-jmsa.png

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值