News for hackers. Stuff that matters.
Re:I only know PHP. How do I write a Web application in Python? by bobsy on Sunday May 06, 2012 @03:23AM (#3934412)
I would love to switch to Python from PHP but I can't. The reason is I keep getting told to learn Python 2. Python 3 has been out for ages!

Basically I am concerned that I will learn something and create app's which within a year will be out of date. I am confused why Python developers are advocating that newbies learn an old and presumably soon to be legacy version of the language.

I remember when this kinda happened with PHP and versions 4 and 5. I still run across hosts who default to PHP4!? WTF? Its 2012!

Is PYthon3 really that new that you shouldn't pick it up or is this developers still refusing to update?

Re:I only know PHP. How do I write a Web application in Python? by eevee on Sunday May 06, 2012 @03:40AM (#3934447)
Python 2 versus 3 isn't anything like PHP 4 versus 5.

The problem is that there are a few minor but backwards-incompatible changes to the syntax in py3. Libraries can't update until all their dependencies update. And web frameworks are some of the most complex software with the most dependencies, so they're updating last.

It's still pretty much the same language behaving in the same way, though. If you know Python 2 really well, it'll take all of five minutes to get accustomed to Python 3. Just don't worry about it and learn 2 until people stop telling you otherwise. :)

Re:I only know PHP. How do I write a Web application in Python? by mkopinsky on Sunday May 06, 2012 @08:56AM (#3934998)
"Don't worry, migration from Python 2 to 3 is really easy. It'll take 5 minutes to learn."

"Migration for libraries from Python 2 to 3 is really hard. It's taken them a few years and counting."

??

Re:I only know PHP. How do I write a Web application in Python? by eevee on Sunday May 06, 2012 @06:44PM (#3936627)
Right. Learning Python 3, once you know 2, is really easy.

Library maintainers have two problems: they have to twiddle their thumbs until all their dependencies have ported, and then they have to get their code running against both 2 and 3. The former is exactly why I'm saying to use 2 for now, and the latter is easy if you only support 2.7 but rather more difficult for projects that still want to run on some archaic thing like 2.3.

Re:I only know PHP. How do I write a Web application in Python? by Luyt on Sunday May 06, 2012 @03:47AM (#3934468)
Python3 isn't much different from Python2. It's not like you have to re-learn Python when you switch from 2 to 3.

In a nutshell: print() has become a function instead of a statement. The standard library has been made more consistent. Built-in iterators are lazy by default. The two string types (str and unicode) are properly redefined as 'bytes' and 'strings'.

Re:I only know PHP. How do I write a Web application in Python? by getoffmalawn on Sunday May 06, 2012 @03:50AM (#3934473)
In practice, for MOST developers, the changes between 2 and 3 are minimal. Offhand, print is a function, and there's no distinction between unicode strings and ascii strings anymore. If you do a lot of "low level" networking involving byte strings, you'll notice the difference, because you can't just jump between bytes and strings anymore.

It's this distinction that's delaying a lot of networking related libraries from porting to Python 3 - basically, it's going to be a long, buggy journey. Libraries such as Twisted, have very old codebases - old enough that some of the practices aren't the best, even for Python 2 code. Upgrading it to Python 3 will introduce quite a few breakages.

There's a lot more that I can't think of right now, but I'm sure someone else can cover off other differences.

There's no reason not to learn both - I use Python 3 for a few personal projects, and Python 2 for work.

Re:I only know PHP. How do I write a Web application in Python? by JDavo on Sunday May 06, 2012 @05:41AM (#3934655)
For the vast majority of projects, upgrading (or working with both PY2 and PY3 at the same time) is not that big of a deal unless the project you're working on is really, really old (2.3 days). At work we run unittests targeting different python versions and the most time I've spent changing a typically 4k loc project's codebase to work on both 2 and 3 has been around 4 hours. The average around 1.
Re:I only know PHP. How do I write a Web application in Python? by Ingaz on Sunday May 06, 2012 @03:52AM (#3934478)
Python 3 is not "really that new" and Python 2.6-2.7 is not "old" in any way.

In fact we have: pre-2.4 (really old, preinstalled on old Redhats), 2.4-2.7, 3.x

Python 3 is curing problem with variable visibility (and if you do not write in "pure" functional way - you will never see this problem) and unicode strings. Other differences is not so "revolutionary".

Re:I only know PHP. How do I write a Web application in Python? by damncabbage on Sunday May 06, 2012 @08:52AM (#3934987)
> (and if you do not write in "pure" functional way - you will never see this problem)

Could you explain this a little more, please?

Re:I only know PHP. How do I write a Web application in Python? by eevee on Sunday May 06, 2012 @07:18PM (#3936760)
I assume he's talking about the `nonlocal` keyword introduced in py3, which allows overwriting names defined in outer-but-not-global scopes.
Re:I only know PHP. How do I write a Web application in Python? by Ingaz on Wednesday May 09, 2012 @06:59PM (#3950940)
Yes, eevee is right.

I'm talking about http://www.python.org/dev/peps/pep-3104

New keyword nonlocal and ability to have better closures.

Re:I only know PHP. How do I write a Web application in Python? by pbreit on Sunday May 06, 2012 @11:39AM (#3935357)
> I am concerned that I will learn something and create app's which within a year will be out of date

Don't worry about that. Start with Python 2 and if you ever have to move to Python 3, it will be fairly easy.

The same thing happened in the PHP world during the switch from 3 to 4 and then 4 to 5. The move from Python 2 to 3 will probably be smoother.

Re:I only know PHP. How do I write a Web application in Python? by megaman821 on Sunday May 06, 2012 @11:11AM (#3935285)
The differences between Python 2.7 and 3.x are going to be minimal. You can mostly write Python 3.x style code in 2.7 and still have access to all of the libraries that have not ported their code yet.