News for hackers. Stuff that matters.
Re:Python 2.7.7 released by niuzeta on Monday June 02, 2014 @12:54PM (#7834450)
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.
Re:Python 2.7.7 released by acdha on Monday June 02, 2014 @01:51PM (#7834778)
Python 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/

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

Re:Python 2.7.7 released by freehunter on Monday June 02, 2014 @03:10PM (#7835343)
The 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.
Re:Python 2.7.7 released by froxle on Monday June 02, 2014 @09:32PM (#7837655)
The 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/

Re:Python 2.7.7 released by wldcordeiro on Sunday June 08, 2014 @06:27PM (#7866157)
It is a great tutorial for someone with some programming experience but for complete beginners it's not adequate.
Re:Python 2.7.7 released by acdha on Monday June 02, 2014 @03:22PM (#7835488)
This 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.
Re:Python 2.7.7 released by wldcordeiro on Tuesday June 03, 2014 @10:29AM (#7840382)
The code in Learn Python the Hard Way is all really easy to port to Python 3 since it's written for new programmers, that said. New programmers won't know that.
Re:Python 2.7.7 released by markdown on Monday June 02, 2014 @07:54PM (#7837296)
Udacity is stuck with 2.7 until GAE supports Python 3.
Re:Python 2.7.7 released by analog31 on Monday June 02, 2014 @11:03PM (#7837932)
Thanks for that link. As of tonight, I'm committed to writing version independent code.
Re:Python 2.7.7 released by BuckRogers on Monday June 02, 2014 @01:06PM (#7834527)
You 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.

Re:Python 2.7.7 released by ak217 on Monday June 02, 2014 @01:46PM (#7834746)
Actually, Unicode handling is broken on Python 2, and works just fine on Python 3. I'm also a Russian user :)

Your code doesn't make any sense. Care to comment on what it means?

Guido didn't do us any favors with his migration strategy, but Python 3.4 is a substantially better and more modern language, so I would suggest developing on it (it's supported out of the box on Ubuntu 14.04 LTS, for example). It's true that app platform providers have not caught up yet, though.

Re:Python 2.7.7 released by dekhn on Monday June 02, 2014 @07:48PM (#7837269)
Yeah. I moved all code dealing with Unicode (in particular, parsing iTunes track names) to Python 3. That was the one part of the language that worked well for me- instead of utf8 codec hell, things just worked.
Re:Python 2.7.7 released by viraptor on Monday June 02, 2014 @01:17PM (#7834579)
> 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.

Re:Python 2.7.7 released by kbd on Monday June 02, 2014 @01:15PM (#7834569)
> 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
Re:Python 2.7.7 released by rspeer on Monday June 02, 2014 @03:37PM (#7835661)
cp866 and cp1251? Something is seriously wrong there. This Russian user's OS is using two different obsolete 1-byte encodings, and claiming not to know anything about UTF-8.

Is he running Python in, say, a Command Prompt window that's maintaining compatibility with a Russian-localized version of MS-DOS?

I can see how he can't move to Python 3, because Unicode support in his environment is basically impossible. That's a deeper problem than just Python. If he's been writing Python 2 code that deals with Russian text, it's probably producing mojibake when run on any machine but his own!

Re:Python 2.7.7 released by zokier on Monday June 02, 2014 @02:39PM (#7835033)
I was going to argue that the vastly improved Unicode support in Py3k would be reason enough to use it. And this is coming from a person who is bilingual with both languages using different, non-7bit-ascii alphabets.
Re:Python 2.7.7 released by nostrademons on Monday June 02, 2014 @01:33PM (#7834677)
Start 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.
Re:Python 2.7.7 released by dragonwriter on Monday June 02, 2014 @01:00PM (#7834491)
While 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.

Re:Python 2.7.7 released by lmm on Monday June 02, 2014 @01:06PM (#7834529)
3.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.
Re:Python 2.7.7 released by takeda on Monday June 02, 2014 @03:07PM (#7835314)
Start 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.

Re:Python 2.7.7 released by JelteF on Monday June 02, 2014 @03:54PM (#7835832)
I'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

Re:Python 2.7.7 released by levesque on Monday June 02, 2014 @01:43PM (#7834730)
They 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.

Re:Python 2.7.7 released by rdtsc on Monday June 02, 2014 @01:04PM (#7834510)
What 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.

Re:Python 2.7.7 released by oblio on Monday June 02, 2014 @01:35PM (#7834685)
Totally 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.
Re:Python 2.7.7 released by wzy on Monday June 02, 2014 @02:08PM (#7834872)
I 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?

Re:Python 2.7.7 released by Scramblejams on Monday June 02, 2014 @05:55PM (#7836727)
As 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.
Re:Python 2.7.7 released by CatMtKing on Monday June 02, 2014 @04:15PM (#7836017)
I 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.
Re:Python 2.7.7 released by Scramblejams on Monday June 02, 2014 @05:50PM (#7836691)
Twisted 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.
Re:Python 2.7.7 released by hcarvalhoalves on Monday June 02, 2014 @02:09PM (#7834876)
It'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.).
Re:Python 2.7.7 released by damon_c on Monday June 02, 2014 @12:57PM (#7834467)
If 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.
Re:Python 2.7.7 released by 0xdeadbeefbabe on Monday June 02, 2014 @01:38PM (#7834710)
I 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.