I’m a newbie to programming and need some help with the set of fixers to refactor code written for Python 3.x into code that can run on a 2.x interpreter.
I have Python 3.2, but the admissions for the Spotify Puzzle’s (http://www.spotify.com/us/jobs/tech/best-before/) requires that the code is written in 2.6. Therefore, I found the 3to2 coverter. I have the “3to2_py3k-1.0.tar.gz” vesion which you can download from here: https://bitbucket.org/amentajo/lib3to2.
The README file tells you to
(…)Run “./3to2” to convert stdin (“-“), files or directories given as
arguments.(…)
The text on this site is identical to the README file.
I understand this I’m supposed to run the commandline and then write:
C:\Python32>3to2 Spotify.py
3to2 is not recognized as an intern or extern command, a program a or batch file.
(Manually translated from norwegian).
I have tried to path to the spesific files, but there is no file that is named “3to2”. I Have tried to path to the “main.py” file and “Spotify.py” directly, and it seems like something happens(Like it takes a tiny bit of a second, and gives no errors), but when I open “Spotify.py” again, nothing have happend to the file.
I appreciate all help.
Thank you spatz, this helped a lot. Finally, I managed to install the package by cd C:\Python32>python.exe setup.py install
Anyway I still have some problems. Take the print("Hello World!") program as an example. When I run python.exe 3to2 HelloWorld.py(it did’t work without the python.exe) it answers:
RefractingTool: Skipping implicit fixer: collections
RefractingTool: Skipping implicit fixer: int
RefractingTool: Skipping implicit fixer: memoryview
RefractingTool: Skipping implicit fixer: printfunction
RefractingTool: Skipping implicit fixer: inittest
RefractingTool: Refactored HelloWorld.py
--- HelloWorld.py (original)
+++ HelloWorld.py (refactored)
@@ -1 +1 @@
-print("Hello World!")
+print u"Hello World!"
RefactoringTool: Files that need to be modified:
RefactoringTool: HelloWorld.py
This is really mixed signals for me. First of all, it seems like it skips some fixers, for instance the printfunction. But later, it definitely looks like it changed print("Hello World!") with print u"Hello World!" as it should. The problem is that when I open this file in IDLE 3.2, the file has the original code. The exact same happens with the Spotify.py file. Is IDLE “smart” enough to change this simple code so it is compatible with 3.x, or doesn’t the 3to2 fixer set works?
SOLUTION:
I figured it out. I had to include -w as an argument. That converted the original file in addition to creating a backup fil .bak.
Thanks to anyone that helped me!
It seems you did not properly install
3to2. To install do the following:.tar.gzfile you downloaded to some directorycdto that directory and runpython setup.py installNow you can
cdto the directory whereSpotify.pyis and run3to2 Spotify.py, and it should work.