简体   繁体   English

在Windows中使用2to3 python

[英]Using 2to3 python in windows

I am fairly new to programming and have been learning python on codecademy. 我对编程相当陌生,一直在codecademy学习python。 I would like to convert a python 2x program to python 3x using 2to3 on the command line but have no idea how to do it. 我想在命令行上使用2to3将python 2x程序转换为python 3x,但不知道该怎么做。 I have looked at various other questions and articles on how to do it but I still do not understand. 我查看了有关如何执行此操作的其他各种问题和文章,但我仍然不明白。 I have python 3.3 installed, and am running windows 8. This is the path to my python 2x program and my path to 2to3. 我已经安装了python 3.3,并且正在运行Windows8。这是python 2x程序的路径,也是2to3的路径。

My program: "C:\\Users\\watt\\Documents\\Tom's Stuff\\Programs\\Python\\python 2 test.py" 我的程序:“ C:\\ Users \\ watt \\ Documents \\ Tom's Stuff \\ Programs \\ Python \\ python 2 test.py”

2to3 Location: "C:\\Python33\\Tools\\Scripts\\2to3.py" 2to3位置:“ C:\\ Python33 \\ Tools \\ Scripts \\ 2to3.py”

Can someone please tell me what I would have to enter into the command line? 有人可以告诉我我必须输入命令行吗?

Thanks in advance... 提前致谢...

You need to run Python, followed by the 2to3 script, followed by tags and arguments. 您需要运行Python,然后运行2to3脚本,然后运行标签和参数。

Running 2to3 on command line looks something like this: 在命令行上运行2to3看起来像这样:

[python] [2tp3.py] [tags] [files to be converted (can be 1+)] [python] [2tp3.py] [标签] [要转换的文件(可以是1+)]

C:\\python33\\python.exe C:\\python33\\Tools\\Scripts\\2to3.py -w C:\\Users\\watt\\Documents\\Tom's Stuff\\Programs\\Python\\python 2 test.py C:\\ python33 \\ python.exe C:\\ python33 \\ Tools \\ Scripts \\ 2to3.py -w C:\\ Users \\ watt \\ Documents \\ Tom's Stuff \\ Programs \\ Python \\ python 2 test.py

By running Python33 followed by 2to3.py, you can run the 2to3 script. 通过运行Python33和2to3.py,可以运行2to3脚本。 Then you add the -w tag to actually convert your program to Python 3. Then you add the files to be converted. 然后,添加-w标记以将程序实际转换为Python3。然后,添加要转换的文件。

The command can be simplified by using changing directory to your Programs folder first. 通过首先将目录更改为Programs文件夹,可以简化命令。

Copy this line to C:\\python33\\Scripts\\2to3.bat : 将此行复制到C:\\python33\\Scripts\\2to3.bat

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

After that you'll be able to use 之后,您将可以使用

2to3 test.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM