Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

What are the differences between python 2.7 and 3.0?

I'm being forced to use python 2.7 in Google App Engine (GAE). I was just curious what the differences in 2.7 to 3.0 are.

I'm also curious if the Treehouse lessons here will be applicable to what i'm doing. Anyone know? Thanks in advance!

Ben

3 Answers

Ben,

The differences between Python 2.7 and 3.? are well documented. The concepts of linear code, all the way through the Object Oriented code are the same in both version. If you study the few commands that are different in the 2 version, such as the input/print and others, then you should have no problems switching between the versions. You can also put tests to find the version (sys.version) and then make code to work in both versions.

Ron

here is an article that outlines the key differences between the 2

here is a wiki page from the python wiki that covers some differences as well

Thanks Stone!

Treehouse uses the latest version of Python. Would I be able to use the skills from these courses in my own development since I'm working with GAE and Python 2.7?

I've already had some difficulties using my own terminal running 2.7, as many of the commands (namely "input" vs "raw_input") are giving me some compiling and syntax errors.

Please advise. Thanks!

Ben

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Things to keep in mind:

  • Write your Python 2 code like it's Python 3
  • To do this, be sure to use the __future__ module as much as possible, especially the print_function, and division features
  • Always define your classes as extending from object. class Foo(object): (Python 2 needs this to avoid Python 1-style classes (ugh) and Python 3 doesn't care)
  • If you have to do things differently based on version, use the six library instead of something like 2to3