4 ms·
huh, as a developer thinking of starting Python, is python 2.X still worthwhile to start with? The python.org even has a subsection for 'starting with 2 or 3',
by niuzeta 12y ago
huh, as a developer thinking of starting Python, is python 2.X still worthwhile to start with? The python.org even has a subsection for 'starting with 2 or 3', and of course they promote 3, but recent posts have made me think twice about starting with the newest.
- damon_c 12y agoIf I were just starting out, I'd go with whichever version the boasted the most examples on Stack Overflow. While more and more are written in 3.x or include both, for now it will be much easier to learn 2.x.
- dragonwriter 12y agoWhile there are significant differences between 2 and 3, mostly they aren't that big of a deal in terms of learning the language. There's no reason you can't learn both simultaneously, and its not hard to learn one from knowing the other, so its probably less important than you might think which you choose to learn first. If you are going to do new greenfield development with no particular expectation of being tied to 2, 3 is probably better, But there's still some things you might wish to leverage that might make knowing 2, and how it differs from 3, useful.
- rdtsc 12y agoWhat libraries are you using? Check their status. Some libraries are not ported to 3.X and many that have been ported are probably not as well tested as their 2.x versions. If you plan to just use pure Python (standard library), then give 3 a try.
- oblio 12y agoTotally agreed. Think about you're going to develop, check if the libraries are there, and if they are, go 3 and don't look back. I see no point in starting from 0 and working with what is already a legacy language - unless there's a hard requirement tying you to Python 2.
- BuckRogers 12y agoYou definitely want 2.7. The best learning material is in 2.7 (LPTHW), all libraries support 2.x but not 3.x, no PyPy that's not in beta, performance on 3.x is less than 2.7 and all online hosts are on 2.7 or earlier (Azure, Google App Engine, etc). Most of the resources available online for help are 2.x. Not to mention the unicode implementation is broken. I was just talking to a Russian user (someone you'd assume would want unicode by default), and Python3 not operating on bytes by default is a mess. He can't move to Python3 due to how unicode is implemented. print sys.getdefaultencoding() # ascii print locale.getpreferredencoding() # cp1251 print sys.stdout.encoding # cp866 print sys.getfilesystemencoding() # mbcs #~ print u"кодировочка!" #~ print u"кодировочка!".encode('cp866') #~ print unicode(u"кодировочка!", 'cp1251') #~ os.rename ('b', u'б') In most things in life, you'd always want the 'latest version', it would be a no-brainer. I wouldn't even bet on the transition to Python3 succeeding until it has- it's been 6 1/2 years already. Use 2.7 and then move to 3.x when and if it ever makes sense. It won't be hard at all to switch as a user, that's not the problem.
- kbd 12y ago> and Python3 not operating on bytes by default is a mess. I'm not arguing that it's not, but I don't how your examples support your point. Would you please explain how your examples show that "strings are unicode" is broken on Python 3? FWIW, here's what I get: Python 2: >>> import sys, locale >>> print(sys.getdefaultencoding()) ascii >>> print(locale.getpreferredencoding()) UTF-8 >>> print(sys.stdout.encoding) UTF-8 >>> print(sys.getfilesystemencoding()) utf-8 In Python 3, the only difference is: >>> print(sys.getdefaultencoding()) utf-8
- viraptor 12y ago> Not to mention the unicode implementation is broken. Can you provide more details? The one thing that python3 did well is actually fixing the unicode/str mixup. You posted some lines of code, but didn't tell exactly what's wrong with it. > Python3 not operating on bytes by default is a mess Why not just use the b'' prefix then and be explicit? > can't move to Python3 due to how unicode is implemented I'd like to see the bugs he raised against python 3 regarding this. There should be no difference in what you can and cannot do using python 2/3. I don't want to call BS on this, but... please provide some specific issues if you're claiming py3 is not usable.
- lmm 12y ago3.x is a much better language to learn with (the difference between strings and bytes is really important, and somewhat obscured in 2.x). If you need some 2.x-only library then use 2.x, but otherwise go with 3.x. I wouldn't put a lot of stock in the angry blog posts we've had lately.
- nostrademons 12y agoStart with 3. Most of the complaints you see on Hacker News are from people who have a large existing codebase in 2.x that they'd need to migrate over, or who need to use an esoteric library that hasn't been ported over. It will probably never make sense for these people to migrate; they have a large fixed cost to update their software, and the benefits won't outweigh them for a long time. You don't have that cost, so you might as well enjoy the benefits.
- 0xdeadbeefbabe 12y agoI agree with those recent posts, and I have lots of 2.X code. But you really ought to consider the broader implications if you are planning to invest a lot of time.
- levesque 12y agoThey are both the same language, and I'd argue the differences are really minor/unimportant when it comes to learning Python. This whole 2 vs 3 has been blown out of proportion by the community. The choice only needs to be done when you know you will use a third party library that only supports Python 2. Some simple libraries can even be ported automatically using the 2to3 tool.
- acdha 12y agoPython 3 is increasingly the better choice. The major exception is if you need a library which hasn't been ported yet but that list continues to shrink: http://python3wos.appspot.com/ http://python3wos.appspot.com/ The good news is that it's increasingly easy to write programs which run on both using newer idioms via __future__ backports, which is often both future proof and a way to write better code using newer language features which many people miss out on due to habit and old tutorials. Lennart Regebro has a wonderful guide covering the changes and how to deal with them as painlessly as possible: http://python3porting.com/differences.html http://python3porting.com/differences.html
- freehunter 12y agoThe biggest problem is many of the best tutorials are written in Python 2.7. Udacity's Intro to CS and Learn Python the Hard Way come to mind.
- acdha 12y agoThis is sadly true, although as Lennart's guide makes it clear many of those can trivially be updated to run on both. I'm hoping the next year leads to a lot of the simple updates happening so tutorial code can run against both — with `from __future__ import absolute_import, division, print_function, unicode_literals` quite a few programs can easily be single-source using only stock Python 2.7 / 3.4 without needing to introduce something like six.
- markdown 12y agoUdacity is stuck with 2.7 until GAE supports Python 3.
- froxle 12y agoThe python.org tutorial[0] is available in both 2 & 3, and is a perfectly great, but often overlooked, resource for learning the language. [0]: https://docs.python.org/3/tutorial/ https://docs.python.org/3/tutorial/
- 12y ago
- wzy 12y agoI too asked myself when starting Python about 2 months ago. I initially started with Python 3.4, then I started experimenting with some code recipes on ActiveState. Then i realized i would need v 2.7 for most of what I was interested in website analysis - Twisted. So now I am torn between the 2, these days because my coding is simple all I have to look for is if I need or don't need a '()' in my print statements. I am glad i am not at the level where I need to worry about how 'bytes' are handled. I do hope this 3 vs. 2 thing gets resolved quickly, I really like the simplicity of Python but for beginners this battle is off-putting Survival of the fittest?
- deleted 12y ago[deleted]
- CatMtKing 12y agoI don't know much about it, but I was under the impression that the new asyncio library in Py3 included callback support -- though it may not have everything you want that's in Twisted.
- Scramblejams 12y agoTwisted is a huge, amazingly capable networking framework that goes way, way beyond just providing async. I say that as a frequent user of it, and I'm not moving to Python 3 until Twisted has.
- Scramblejams 12y agoAs a happy Twisted user, my advice is to just stick with Python 2 and enjoy it. If you end up having to deal with Unicode, then do a bit of research on what to watch out for. If Twisted is up your application's alley, it's worth every bit of effort to learn it and use it. I started learning it in '03 and the investment has been repaid many times over.
- hcarvalhoalves 12y agoIt's trivial to upgrade from 2.7 to 3, you can pick based on the availability of the libraries you plan to use. If all you need has been ported to 3 just go with it, otherwise you can use 2.7 and make your code future-proof by importing some things from __future__ (the print function, unicode literals, etc.).
- takeda 12y agoStart with 3. The libraries are not that big of a problem, and since you plan to start with it, chances are you probably won't even have a need to use these libraries anyway (you don't have any existing codebase that relies on 2.x or these libraries). The language is much cleaner in version 3 and from what I read and my personal experience it is much easier to make code written for version 3 work with 2.7 than the other way.
- JelteF 12y agoI've just (1 hour ago) updated my Python 3 library [1] to support Python 2.7 as well. All I needed to do was pass it through the awkwardduet, the 3to2 fork, and everything just worked. Writing in Python 3 feels way cleaner though. The objects super calls that didn't need to know their current class was great to use. [1] https://pypi.python.org/pypi/PyLaTeX https://pypi.python.org/pypi/PyLaTeX