简体   繁体   English

无法弄清楚如何使用2to3 Python转换器

[英]Can't figure out how to use 2to3 Python converter

I've seen other answers for this on Stack, but they aren't helping. 我已经在Stack上看到了其他答案,但是它们没有帮助。

I have a Python 2.7 script that I need converted to work with Python 3. It seems like using 2to3 shouldn't be this difficult, but I can't figure it out. 我有一个需要转换为与Python 3一起使用的Python 2.7脚本。似乎使用2to3并不难,但我无法弄清楚。 In the Windows command line, I try typing "python C:\\Python27\\Tools\\Scripts\\2to3.py (path to my file)" and it says "Invalid syntax" and has a little carrot pointing to the C in the first file path. 在Windows命令行中,我尝试键入“ python C:\\ Python27 \\ Tools \\ Scripts \\ 2to3.py(我的文件的路径)”,它显示“语法无效”,并且在第一个文件中有一点胡萝卜指向C路径。

I also try opening the IDLE shell and typing "$ 2to3 (path to my script)", which also says "Invalid syntax" and highlights the $. 我还尝试打开IDLE shell,然后键入“ $ 2to3(脚本的路径)”,它也显示“无效语法”并突出显示$。 So I get rid of the $ and try again, and then it highlights the "2to3" with Invalid Syntax. 因此,我放弃了$并重试,然后它用无效的语法突出显示了“ 2to3”。

I've seen other answers as well, and none come even close to working. 我也看到了其他答案,但没有一个甚至无法实现。 I feel like an idiot for not getting this. 我感觉像个白痴,没有得到这个。 What am I missing? 我想念什么? Can someone explain it like I'm five? 有人可以像我五岁那样解释它吗?

(I'm fairly new to programming, but I've been doing pretty well writing scripts in Python. I have no idea why THIS is the thing I'm struggling with.) (我刚接触编程,但是我用Python编写脚本一直做得很好。我不知道为什么这是我一直在努力的事情。)

Does this work for you? 这对您有用吗?

python C:\Python27\Tools\scripts\2to3.py -w <your_file>.py

This will make the necessary changes to make you <your_file>.py to make it compatible with python3 and overwrite the original file 这将进行必要的更改,以使您<your_file>.py使其与python3兼容并覆盖原始文件

See 2to3 documentation 请参阅2to3文档

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

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