Python Forum
Resources for converting Python 2.x code to 3.x
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Resources for converting Python 2.x code to 3.x
#1
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?  
Reply
#2
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
Reply
#3
(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.
Reply
#4
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
Reply
#5
Sure i was misunderstanding that part.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Converting python to FileMaker DWolf 6 1,685 Sep-22-2022, 03:40 AM
Last Post: DWolf
  Resources for printing tabledata-Linux and Windows hammer 4 1,413 Apr-25-2022, 12:09 PM
Last Post: hammer
  Wanted to tag azure resources with creator name raham3406 0 1,440 Apr-25-2021, 02:24 PM
Last Post: raham3406
  Need learning resources for Python distribution gretchenfrage 2 2,125 Nov-12-2020, 06:42 PM
Last Post: gretchenfrage
  Resources for working with images and video? SheCurvesMobius 0 1,399 Mar-28-2020, 08:43 PM
Last Post: SheCurvesMobius
  Converting SQL Code To Python Code Query eddywinch82 13 29,175 Feb-15-2020, 06:42 PM
Last Post: buran
  Converting python to c# benahmadi 1 2,641 Oct-22-2019, 09:50 PM
Last Post: micseydel
  converting array to and from string in python 3.7.2 srm 5 6,170 Jul-03-2019, 01:11 PM
Last Post: snippsat
  help with converting C# function to Python korenron 17 11,326 May-19-2019, 10:26 AM
Last Post: Gribouillis
  Converting R code to python mcva 2 12,513 Mar-09-2019, 04:01 PM
Last Post: mcva

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020