

Ask HN: start with python 2.6 or 3? - jgamman

if you were learning python right now as your first language and you wanted it to play well with others (django, scipy, matplotlib, GAE etc) - do you start with something stable with loads of documentation and then migrate to python 3 (heck it's 3.1 already) or do you skip the mental overhead of unlearning some things that'll get baked in by using 2.6?
======
etal
The official guideline (<http://python.org/download/>) is fine:

 _Note that both Python 2.6 and 3.1 are considered stable production releases,
but if you don't know which version to use, start with Python 2.6 since more
existing third party software is compatible with Python 2 than Python 3 right
now._

If you're just learning to program now, you'll have an easier time if you
stick to the officially sanctioned features of Python, rather picking up bad
habits from deprecated back roads. There aren't many of them in Python 2
compared to some other languages, but if you want to be safe, Python 3 was
meant to eliminate as many of those as possible. You'll get a similar benefit
if you follow the official Python 2.6 tutorial first, before reading
introductory Python books that were written before Python 2.6 was released.

To be super specific, these are the things that you should try to stay up to
date on:

1\. Unicode support in strings

2\. "New-style" versus "old-style" classes

3\. The "with" statement, and context managers

4\. Generator functions and expressions, versus list comprehensions and plain
ol' for loops

If you watch out for these, and read the "What's New in Python X.Y" documents
for each version between the one you started on and the newest release, the
transition shouldn't be too hard.

The projects you're depending on may also offer some hints about when they'll
do the 3.X transition. SciPy depends on Numpy, which depends heavily on the
Python 2.X C extension API and will take a long time to convert. Django is
basically pure Python and can probably convert sooner. GAE is Google's
infrastructure and will probably be 2.X for years.

~~~
jgamman
thanks for that and to all the other HNers that took the time to reply - i
think i'll go with 2.6 but book a recurring task to make sure i'm at least
aware of the changes in moving to 3.1

------
anamax
> do you skip the mental overhead of unlearning some things that'll get baked
> in by using 2.6

You're thinking that this is a significant thing. It isn't, at least not if
you become a somewhat competent programmer.

Programming has very little to do with programming language details.

In fact, there's a reasonable argument that the more languages you know, the
better programmer you're likely to be. Unfortunately, the difference between
2.6 and 3.1 probably isn't enough to help you in this regard. It is, however,
enough to help you see some issues wrt language design.

------
GeneralMaximus
If all the libraries you need are already available for Python 3, then use
Python 3. Otherwise, fall back to the 2.x series. Be practical. Evaluate your
own needs before you listen to somebody else. The 2.x branch is here to stay
for quite a long time (I'm guessing 2 to 5 years).

<BEGIN RAMBLING> If the users don't drive the library authors/maintainers to
make their code compatible with Python 3, then we'll have to wait a very
_very_ long time for the 2.x branch to go away. I'm not saying Python 2.x is
bad in any way. It just takes too much effort to maintain separate codebases
for separate versions of the language. Also, I'm sure the language developers
could do something much more useful with their time if they focussed on one
version of the CPython implementation. <END RAMBLING>

~~~
dtf
This is true. I would have said 2.6, because library support for 3.0 is quite
wanting. But you're absolutely right: without demand it will never get there.

------
pmorici
You can use a lot Python 3 features in 2.6 and later. This document,
<http://docs.python.org/3.0/whatsnew/3.0.html> describes the difference
between the two. So while I agree with the other posters that it it would be
better to start with 2.6 I also think you could minimize your upgrade pain by
knowing the differences and doing as many things as you can in the Python 3
style.

------
jcsalterego
Practically speaking, if you want to leverage a lot of those
libraries/frameworks you mentioned, 2.x is the way to go. However, the major
syntactical and core differences that break backwards compatibility in Python
3000 (<http://docs.python.org/3.0/whatsnew/3.0.html>,
<http://docs.python.org/3.1/whatsnew/3.1.html>) should be in the back of the
your mind.

After working in a bit of py3k, I've found that "small things" such as using
print() as a function rather than a statement comes more naturally than in
Python 2.x, mostly because the latter doesn't complain about it.

Other things like xrange()'s departure in py3k as range() becomes a true
iterator -- that's something you'll have to be cognizant of.

My advice is if you want to get a large project done, with support from
popular and existing frameworks, go with the 2.x branch. If you're whipping up
some disposable scripts, practice with py3k. And even if you're not, fire up
py3k anyway.

One of the great Google Summer of Code projects this year is the inverse to
the 2to3 tool -- 3to2 -- with the forward-thinking intention of making it
easier to maintain one branch of code in py3k. It isn't a magic bullet by any
means, but should definitely encourage the transition from Python 2.x to 3000.

------
pavelludiq
I'd go with 2.x, simply because theres more code written in it, and more code
one can read and learn from. Especially if its a first language, its good to
learn from real code. In the beginning it was hard for me to read source code,
but eventually i started "getting it". 2.x will eventually evolve in to 3.x
with 2.7 and 2.8 so its safe to go with it for now. Plus the mental overhead
is not that big, 3 is not that much different from 2.x, its still python.

------
rg123
Since it will take a while for the 3rd party libraries to be ported to 3.x,
start with 2.6. The versions are not different enough for it to be a big
problem either way you learn them - but there are more books out for 2.x -
like the Python in a Nutshell book, which I find to be the best reference
(though not the best book for beginner programmers). Then, you can refer to
the "What's New in Version x" entries in the documentation on the Python site
to learn the later versions.

------
timwiseman
That depends on what you need. In general, I would recommend 3.0. It is more
modern and has some nice enhancements and is the way to go in the long run.

With that said, some libraries still haven't made it to Python 2.6 let alone
3.0. For instance, I make use of NumPy which was compatible with 2.54 but not
2.6 the last time I checked.

------
krishgy
You start with 2.6. When you start working with python, you are not just going
to use the libraries which comes with language. you need to use plenty of
projects or modules developed by other users.

Start with 2.6 but consider 3.0 changes in mind like exception base, print
statement. Start practice 3.0 convention using 2.6.

I think, atleast two to three years of development for people to port all
their projects to python 3.0.

Sure, you will miss many things, but you are on the way.

------
CyberFonic
If only wxPython were to be available for Python v3.1 then I would choose
that. Because it isn't yet, I prefer v2.6 and use "from future import ...."

If you don't choose to use any libraries that require v2.6 or older right now,
then I'd encourage the choice of v3.1. I'm hoping all libraries will run with
v3.1 given enough time.

------
llimllib
I would start with 2.6. The changes are not all that drastic between the two,
and there's almost no software available for python 3.

------
babo
There is no point to lament, take whatever you want, it's not a problem to
switch either way.

------
TweedHeads
Go with 3.

Being a trailblazer can reap rewards in the long run.

~~~
jey
No, if you're a newbie, make things easy on yourself and use 2.6. Once you've
got some experience under your belt you'll be able to _easily_ pick up 3.0.

