Resources for converting Python 2.x code to 3.x - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Resources for converting Python 2.x code to 3.x (/thread-3185.html) |
Resources for converting Python 2.x code to 3.x - Luke_Drillbrain - May-03-2017 Resources for converting Python 2.x code to 3.x I don't intend to use Python 2.x. I'll be writing all my projects in 3.x. However, sometimes I look up code samples to find solutions to problems. Why reinvent the wheel if someone else has already created code for a certain task and has made it available? Of course, there's always the chance that I'll find exactly the code I need, except that it's written in 2.x. For that reason, I've looked up the differences between the two versions. I found this page: https://docs.python.org/3.0/whatsnew/3.0.html It doesn't appear to cover tkinter, however, so I'll be looking up a page on that too. Is there anything else I should keep in mind? Are there any other good resources in the event that I need to convert Python 2.x code to 3.x? RE: Resources for converting Python 2.x code to 3.x - nilamo - May-03-2017 For most things, the 2to3.py tool can convert code for you. So you can save the snippet you find to a temporary file, and run the tool against it to see the new version. https://docs.python.org/2/library/2to3.html RE: Resources for converting Python 2.x code to 3.x - snippsat - May-03-2017 (May-03-2017, 05:59 PM)nilamo Wrote: So you can save the snippet you find to a temporary file, and run the tool against it to see the new version.2to3 make a temporary file automatically when use write 2to3 -w foo.py After run foo.py will be the Python 3 version,and backup Python 2 version will be foo.py.bak .
RE: Resources for converting Python 2.x code to 3.x - nilamo - May-03-2017 Right, but if you're looking at a webpage with code on it, you still need to save that code to a temporary file... otherwise how do you run 2to3 against it? :p RE: Resources for converting Python 2.x code to 3.x - snippsat - May-03-2017 Sure i was misunderstanding that part. |