Python 2 or Python 3


(Daniel Hollands) #1

As I’m sure the regulars here will know, @Twisted and I are working on a little Raspberry Pi project together. For me it’s an excuse to get into the maker scene (I guess I should join FizzPop or something), and for @Twisted it’s an opportunity to learn coding.

Now, for various reasons, we’ve decided that we need to learn Python. It seems to be a nice language for beginners (with teachers being rather fond of it for this reason), and appears to be the language of choice for all things Pi and GPIO related things.

From what I understand, one of the main differences between Ruby (which is the language I use professionally) and Python is:

  • with Ruby you’ve got multiple ways of solving a problem, and can choose your syntax based on what reads the best within the context that you’re working

  • with Python there is one way of doing things, and only one way.

OK, fine - only, that’s not strictly true on the Pythons side, is it?

From what I understand, the Python community is split down the middle, with part being strong supporters of Python 2, and the rest being supporters of Python 3.

This leaves @Twisted and I in a difficult position, as we don’t know which of the two we should learn, or even how to tell the difference.

Personally, based simply on the idea that larger numbers are better, I would have opted to go for Python 3, but having chosen Learn Python The Hard Way as our tutor, it states:

A programmer may try to get you to install Python 3 and learn that. Say, “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. I repeat, do not use Python 3. Python 3 is not used very much, and if you learn Python 2 you can easily learn Python 3 when you need it. If you learn Python 3 then you’ll still have to learn Python 2 to get anything done. Just learn Python 2 and ignore people saying Python 3 is the future.

Long story short, we’re a bit lost and not sure what to do - please shower us with your wisdom.


(Matt Andrews) #2

That Learn Python book is pretty old now and I remember on reddit, /r/python discussed removing that book/advice from their sidebar because it’s quite outdated these days.

If you don’t already know Python, why learn an older version? The differences between 2 and 3 aren’t that insurmountable (and lots of them make sense, like fixing the print function). You might find a few modules that don’t work the way you’d expect but I think you should check out the exciting future :slight_smile:


(Daniel Hollands) #3

Can you suggest a better book/resource to learn from?


(Andy Wootton) #4

I asked the same question due to similar warnings and went with 3. Nothing caused me to regret the decision in the short distance I travelled. If the original designer thinks there are things worth fixing that justify breaking compatibility then I believe him.

I found the official online Python docs to be very good.

I came across the intriguing opinion a couple of days ago that Ruby is really a Lisp.


(Matt Andrews) #5

I don’t think it’s one to skip (it’s very well respected), just that people often cite his advice about Python 3 and I think that particular quote hasn’t aged very well. Still worth reading in general!


(Andy Wootton) #6

And the MIT video lectures for engineers looked pretty good, until I found the older ones in Scheme LISP and got distracted.

I seem to have skipped over the “gentle but intense” prequel http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-189-a-gentle-introduction-to-programming-using-python-january-iap-2011/

This is the one I started http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00sc-introduction-to-computer-science-and-programming-spring-2011/ Unlike his students, I loved his dry sense of humour.


(Steve Jalim) #7

Python 3 - if you’re handling anything in Unicode, you’ll come to hate how py2 does it

Source: 9 years of hating python 2’s Unicode handling :slight_smile:


(Michael Brett) #8

I can recommend ‘Learning Python’ by Mark Lutz. I have the 4th Edition that covers both Python 3 and Python 2.6. The reasoning for this is that if one were intending to use Python professionally there is every chance that one would come across legacy 2.X code. The main thrust of the book is 3.X, though.

I can also recommend the Codecademy Python track for someone just getting into programming. It’s pretty accessible and gives a broad introduction to the language.

I really dig Python, I just wish it had JavaScript’s position in the browser. Don’t flame me! :blush:


(Andy Wootton) #9

Just waiting for the new HTTP :slight_smile:


(Steve Pitchford) #10

Out of interest - How is Python 3 with things like PyGame and WX ( or whatever Python uses for GUI apps now )?


(Daniel Hollands) #11

I’m thinking of buying Automate the Boring Stuff with Python (amazon). It’s Python 3, fairly recent, and appears to be aimed at total beginners.


(Andy Wootton) #12

https://wiki.python.org/moin/Python2orPython3