2

I am fairly new to programming and have been learning python on codecademy. 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. 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.

My program: "C:\Users\watt\Documents\Tom's Stuff\Programs\Python\python 2 test.py"

2to3 Location: "C:\Python33\Tools\Scripts\2to3.py"

Can someone please tell me what I would have to enter into the command line?

Thanks in advance...

Tom
  • 145
  • 2
  • 6

2 Answers2

1

You need to run Python, followed by the 2to3 script, followed by tags and arguments.

Running 2to3 on command line looks something like this:

[python] [2tp3.py] [tags] [files to be converted (can be 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

By running Python33 followed by 2to3.py, you can run the 2to3 script. Then you add the -w tag to actually convert your program to Python 3. Then you add the files to be converted.

The command can be simplified by using changing directory to your Programs folder first.

Matthew Stamy
  • 1,114
  • 1
  • 7
  • 9
0

Copy this line to C:\python33\Scripts\2to3.bat:

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

After that you'll be able to use

2to3 test.py
Antony Hatchkins
  • 31,947
  • 10
  • 111
  • 111