

Beginner Learning Python: 2.7 or 3? - jhacks

I have taken the dive to learn Python (currently only experience I have is HTML, CSS, JavaScript, jQuery) and I'm using Learn Python The Hard Way.<p>However, this has me using Python 2.7 and I know that this is the last of Python 2.x and Python is what I might need to know going forward.<p>Should I look somewhere else to learn (I've gotten just about halfway through LPTHW) or stick through this? I guess it depends how different they are and if it's worth learning Python 2.7 if I'll just be unlearning and relearning certain aspects.<p>What should I do?
======
willvarfar
There's very little to unlearn; go with 2.7 and move over to 3.x with the rest
of us when we all get around to it, if we ever do ;)

~~~
llambda
> if we ever do

No kidding... Here we are, how many years after the release of Python 3? And
still, there are many libraries that have yet to be ported to Python 3. These
deficiencies make Python 3 an impossible choice for some tasks. The slow
adoption of Python 3 is not without reason as many have pointed out, although
Armin Ronacher's recent blog post[1] stands out as one of the better
illustrations of the frustrations with Python 3. I have to say, as a
Pythonista, I am worried about Python. I wonder if things will become
increasingly fragmented...

[1] <http://lucumr.pocoo.org/2011/12/7/thoughts-on-python3/>

~~~
buster
The adoption rate is expected, people should stop complain about the python3
situation when it's not that bad.

[http://sayspy.blogspot.com/2011/01/my-semi-regular-
reminder-...](http://sayspy.blogspot.com/2011/01/my-semi-regular-reminder-
that-python-3.html)

~~~
wycats
It looks like a patch for Django was just finished relatively recently.

For what it's worth, based on my experience with Ruby 1.8/1.9 in Rails, which
is a smaller language change that Py2=>Py3, it will take years and a lot of
community work before Django on Python 3 is a plausible solution.

Rails officially supported Ruby 1.9 as early as Rails 2.3 (which was released
in February 2009), but a large number of commonly used packages weren't really
working for some time after that. Additionally, we made a number of mistakes
our initial Ruby 1.9 support (in Rails 2.3), which we corrected in Rails 3.0.

My guess (again, based on my experience with false starts in Rails) is that
merging the patch in question will take a while, and that it will require some
time after the patch is initially merged before people consider Py3 a valid
target for Django apps.

~~~
jnbiche
I don't know Ruby, but was the difference between Ruby 1.8 and 1.9 as drastic
as the change between Python 2.7 and 3.0? Programs written in Python 3.0 are
not backwards compatible. Is it the same with programs written in Ruby 1.9?
I'm really asking -- I don't know the answer.

~~~
wycats
Ruby did us a big favor and made it possible to implement something like Rails
in a way that switched between Ruby 1.8 and 1.9 at runtime. There are no
changes to the 1.9 parser that cause it to puke on 1.8 syntax.

My understanding is that in Python, you need to use the 2to3 tool for a
program of any non-trivial size to have a single codebase that targets both.
Please correct me if I'm wrong, as I'm only picking this up by osmosis with
the Python community.

Ruby 1.9 is also significantly more runtime compatible with Ruby 1.8 than
Python 3 is with Python 2. For example, the object model and semantics for
creating classes and object is entirely unchanged between Ruby 1.8 and Ruby
1.9. The Unicode change took great pains to remain compatible with programs
using BINARY data for ASCII-only characters, for instance (I personally
believe that this was a mistake going forward, but it results in better-than-
expected backwards compatibility with Ruby 1.8 programs mixing source code and
external ASCII-only data).

As a result, even though Python 3 was released around the same time as Ruby
1.9.1 (the first stable Ruby 1.9 release), the Ruby community is much further
along the adoption curve than Python is.

~~~
jnbiche
Sorry for the delayed response -- I do want to respond to several points.
First, you're sort of correct that you need the 2to3 tool for a program to
target Python 2 and Python 3. There are certain programming techniques (such
as "from __future__ import *) that will allow you to write you code in such a
way that it will run on both Python 2 and 3, although I've not used these on
any project of size. But if you wrote your code using plain vanilla 2.x, then
you'd need to use the 2to3 tool, although again I've not used it myself and
have heard mixed reviews. Unicode is probably the biggest change from Python 2
to 3 that introduces incompatibilities, although I think there are tricks for
dealing with that as well. I like Ruby's approach to Unicode based on what you
described. Why do you think this is a mistake? I expect you are correct that
Ruby is much further along in moving from 1.8 to 1.9, because it sounds like
Ruby has handled the upgrade path well (to be honest, I'm not sure Python
has).

------
ghewgill
I thought I was on Stack Overflow for a moment, because this question always
seems to come up.

[http://stackoverflow.com/questions/5478518/python-2-or-
pytho...](http://stackoverflow.com/questions/5478518/python-2-or-
python-3-which-should-i-begin-with)
[http://stackoverflow.com/questions/170921/to-learn-
python-2-...](http://stackoverflow.com/questions/170921/to-learn-
python-2-then-3-or-3-from-the-start)
[http://stackoverflow.com/questions/1222782/should-i-start-
wi...](http://stackoverflow.com/questions/1222782/should-i-start-with-
python-3-0) [http://stackoverflow.com/questions/2090820/what-version-
of-p...](http://stackoverflow.com/questions/2090820/what-version-of-python-
should-i-use-if-im-a-new-to-python)

------
avb_wkyhu
Stick with Python 2.7 at the moment; there are many reasons for this which I
will not go into. But, later on if the community/if you decide to switch more
towards Python 3, then you will not be 'unlearning' much.

I recommend LPtHW and then Dive into Python. After going through those two
books you will have a really goo grasp on the Python Programming Language.
After which start coding and (possibly) get involved in some Python-based open
source project (or at least study the code a bit).

~~~
jnbiche
May I also recommend How to Think Like a Computer Scientist, Python version,
2nd edition? This edition uses Python 2. _.

I agree with everyone recommending Python 2.7, but do be sure you use the
latest iteration of the Python 2._ series. Python 2.4 and even 2.5 are missing
some great new features, many of which show up in Python 3.0. To me, Python
2.7 is the best of both worlds -- all of Python 2.x's great features and
familiarity, combined with most of the real needed changes in Python 3.0.

I totally agree with Armin when he writes that there should be a Python 2.8
and 2.9. A better upgrade path is needed.

------
jhacks
Thanks for all the replies everyone! It definitely seems like it'd be
worthwhile just going through and learning 2.7 then and using related
libraries to create what I want (once I've learned and am able to do so).

However, this has me thinking. It seems like Ruby (and related frameworks,
like Rails) don't have the backwards-compatibility issue that is seemingly
plaguing Python?

The newest version of Ruby was easily adopted (compared to Python 3) as it
remained backwards-compatible. Even upon researching the next evolution of
Ruby (2), it seems that it won't be huge leap and, again, will remain
backwards-compatible.

My question is... if I'm looking to start building a website now and use
Python 2.7 (and likely Django), what would I do when the time comes and Python
3 is really the go-to version?

Would I need to rewrite the code entirely? Will the older code ever become
compatible or easily transitioned?

It seems like Ruby would be the better choice to avoid possible fragmentation
issues?

I could be entirely wrong here though. So, please, if someone could help me
with this, that would be great. I went through some of Learn Ruby the Hard
Way. And I'm willing to switch over to Ruby.

I like them both in different ways in terms of syntax/readability. But I don't
know enough to really make a decision beyond that.

But this Python fragmentation between 2 and 3 makes me worried. I'd feel safer
choosing to learn Ruby. I don't know though.

~~~
karlzt
Once you learn Python version:X, you won't care about what version you're
using.

Forget about the version crap and focus on learning.

------
cschmidt
Keep going. Until the important libraries catch up, you should be using 2.7
for doing most projects at the moment. You won't have wasted much learning in
the mean time.

Happy New Year.

~~~
redsymbol
_Keep going. Until the important libraries catch up, you should be using
2.7..._

It's true some important Python libraries still only work on 2.X. And, as
someone who's been writing the majority of my real-world production code in
Python 3 for over nine months now, I've found it's not necessarily a barrier.

So, for those of you not coding in 3 but would like to, what are these missing
"important libraries"? What Python libraries do you need, that do not have
quality ports to Py3K yet?

~~~
cschmidt
For me, Django.

------
adolfoabegg
From Learn Python The Hard Way:
<http://learnpythonthehardway.org/book/ex0.html>

A programmer may try to get you to install Python 3 and learn that. You should
tell them, "When all of the python code on your computer is Python 3, then
I'll try to learn it." That should keep them busy for about 10 years.

------
latchkey
Is the goal here to learn how to write code in Python or to learn the
specifics of each version of the language? If the goal is to just learn
Python, I don't think it really matters which version you learn since the
general basics of the language are pretty much the same between versions. In
other words, a for loop is still a for loop.

Asking Google came up with this link:
<http://wiki.python.org/moin/Python2orPython3>

I'd personally start with 2.x so that you can understand the history of Python
and then make sure to have an understanding of what is changing in 3 via links
like this: <http://docs.python.org/py3k/whatsnew/3.0.html>

Finally, if this is for a job, I guess one thing would be to see what the
requirements of the job are. If you need to use Python 3 for your job, your
best bet is probably to learn Python 3. =)

------
celer
The difference between 2.7 and 3 is, to be honest, nothing big in terms of
programming. I use both mostly without noticing the difference, because some
libraries are still on old versions. For now, use import __future__ to help
ease the transition and don't stress.

------
thealistra
If your code heavily uses unicode texts, it will be easier to start with
python 3, because all the iterators word on wide-chars instead of byte ones,
and you don't have do some magic to handle them properly.

------
sitkack
2.7 if you want to release anything AND consume other libraries. 3 if you
never intend on using other than a learning exercise or will write everything
from scratch.

------
veyron
What versions of python are on your machine?

My MBP (leopard -> snow leopard -> lion) has python versions 2.5, 2.6, and 2.7
(and there's a nice way to change the default python version). I fully suspect
python3 is not there by default.

------
pmb
New projects should go with Python 3, if possible. But really, the two
languages are not very far apart. Do whichever if you are just learning and
want to make small temporary things.

