tags:

views:

434

answers:

5

G'day,

I'm wanting to go back to Python after not using it for a while and I saw this question "Python Version for a Newbie" while wondering about getting back into Python 2.6 or Python 3.

Almost all of the questions' answers were along the lines that most of the code out there, libraries, legacy systems, etc., is 2.5 or 2.6 rather than 3 so start with 2.x now and then head towards 3 later on.

Given that the question and all answers date from early December 2008 I was wondering is this still the case?

Should someone who wants to get back into Python maybe start off with 2.6 and then head towards 3 later on?

+2  A: 

If you want to use only standard library then try Python 3.1. If you want to use others libraries/frameworks then they dictate the version to use. For example web2py framework will work best on 2.5.

Michał Niklas
+1  A: 

The problem is, if you started with 2.4 or more it is better if you start from there, so you'll get on track faster, after some time when you feel comfortable with you code you can try 3.0 and find out what did they change and learn the new style.

I for once still code in 2.6 style and follow those guidelines, still haven't seen the changes in 3.0

Lex
+3  A: 

Depends on the amount of libraries you're going to use.

  • Raw Python, or all libs are available for Py3k - go for it without any doubts.

  • Python code distributed as standalone app (using PyInstaller), relying on some GUI lib, XML-lib, win32api etc - double check if all libs are available at least as betas for Py3k. Chances are still quite high that some older lib is not available for Python 3.x, and either you port it by yourself to new Python version, or you switch to some other lib or - stick to Python 2.6 for a while.

Abgan
+9  A: 

Yes. Virtually all live production systems will use 2.5/2.6 for a long time yet. There's no point learning 3.0, only to have to downgrade it because your host doesn't support it.

95% of what you will learn in 2.5/2.6 is applicable to 3 anyway.

Jon Hadley
+1: Test with the -3 option to see where you'll run afoul of Python 3.
S.Lott
+2  A: 

Hi Rob,

I would say that Python 2.4 is the safest to learn, but the changes from 2.4->2.5->2.6 make some small progress towards Python 3.x, even if they may never make it (if I recall there will be some more steps?).

Python 3.1 can be used if you own a dedicated server and intend to build your own applications from the ground up. WSGI does support this, but I wouldn't recommend it.

As has already been said, I would learn the Python 2.5 or Python 2.6 style, but I would make a few changes.

Look at the Python 3 style regarding brackets.

e.g. The print function in 2.x has always been just

print "Hello World"

Where as in 3.x you need to enclose it

print("Hello World")

This is probably a good practice to pick up on, but things like Exceptions will cause issues if you use 3.x in 2.x. I know it's probably a bit confusing, but if you make sure you wrap your functions (additional brackets shouldn't really hurt most things) so that nothing is bare (bare like the first code snippet above), then it'll help with the transition.

Swixel