I have a small project I want to try porting to Python 3 - how do I go about this?
I have made made the code run without warnings using python2.6 -3
(mostly removing .has_key()
calls), but I am not sure of the best way to use the 2to3 tool.
Use the 2to3 tool to convert this source code to 3.0 syntax. Do not manually edit the output!
Running 2to3 something.py
outputs a diff, which isn't useful on it's own. Using the --write
flag overwrites something.py and creates a backup.. It seems like I have to do..
2to3 something.py
python3.0 something.py
mv something.py.bak something.py
vim something.py
# repeat
..which is a bit round-a-bout - ideally I could do something like..
mv something.py py2.6_something.py # once
2to3 py2.6_something.py --write-file something.py
vim py2.6_something.py
# repeat