News for hackers. Stuff that matters.
Re:Python 3.5.0 by redsymbol on Sunday September 13, 2015 @01:43PM (#10212123)
Python 3 keeps getting better and better. I've been writing more code in Python 3 than 2 for about three years now, and I absolutely love it. When I have to write code in 2.7 now, it feels like shifting from fifth gear down to second.
Re:Python 3.5.0 by rizwank on Sunday September 13, 2015 @03:05PM (#10212438)
Is Py3 ready for prime time? Do all the right libraries have support now?
Re:Python 3.5.0 by vikp on Sunday September 13, 2015 @03:09PM (#10212452)
Yes -- I write ~95% of my python code in 3, and scrapy is the only library I commonly use that doesn't support it. Here's a listing of package compatibility: http://py3readiness.org/.
Re:Python 3.5.0 by kodr on Sunday September 13, 2015 @03:17PM (#10212473)
Re:Python 3.5.0 by foob on Sunday September 13, 2015 @04:46PM (#10212743)
In most cases, yes. There are libraries that you might want to use that don't support it yet but the vast majority do. Personally, I'm anxiously waiting for Fabric 2 which has been pending for a long time. This is a good resource for figuring out whether the libraries you need are ready: http://py3readiness.org
Re:Python 3.5.0 by jay_kyburz on Sunday September 13, 2015 @04:44PM (#10212740)
Unfortunately I'm stuck on 2.7 until Google updates App Engine
Re:Python 3.5.0 by wyldfire on Sunday September 13, 2015 @11:00PM (#10213496)
Most of the time I find it pretty easy to make it compatible with both 2.7 and 3.4. Usually just a few "from __future__ import print_function" and a few other tips.

If your codebase is large, it can feel daunting, but it's not usually that bad.

Re:Python 3.5.0 by nickysielicki on Sunday September 13, 2015 @03:26PM (#10212490)
It's been ready for prime time for the past 3 years.
Re:Python 3.5.0 by nstart on Monday September 14, 2015 @12:12AM (#10213602)
Py3 has been prime time for a while now. Been using it full time since Py 3.3 for all my work and I haven't had any issues with it. There were some external libraries such as the library given by a twilio competitor that were incompatible, but easily fixed (almost exclusively, encoding issues).

Although, I still find myself running tests and cursing at the fact that I keep writing print "string" without the brackets :D

Re:Python 3.5.0 by wfunction on Sunday September 13, 2015 @04:26PM (#10212696)
> When I have to write code in 2.7 now, it feels like shifting from fifth gear down to second.

You mean, second gear up to fifth?

I tried writing some Python 3 code and the lack of parameter tuple unpacking by itself stunned me and drove me crazy, never mind other stuff. Python 3 seems very user-unfriendly compared to Python 2. Won't touch it with a ten foot pole unless my life depends on it.

Re:Python 3.5.0 by orf on Sunday September 13, 2015 @05:17PM (#10212813)
I've been using Python for 7+ years, and I had no idea parameter tuple unpacking was a thing. Never once seen any code that uses it, or seen anyone mention it. If you think the (rightful) removal of a hardly used feature[1] that has some big problems is a blocking issue then I feel sorry for you. Py3 is awesome.

1. https://www.python.org/dev/peps/pep-3113/

Re:Python 3.5.0 by dvlsg on Sunday September 13, 2015 @07:23PM (#10213109)
Interesting. Javascript is actually adding something very similar, calling it destructuring. It's actually quite handy - although admittedly more handy for destructuring object arguments than array arguments.
Re:Python 3.5.0 by ben336 on Sunday September 13, 2015 @07:42PM (#10213143)
Python 2 & 3 have destructuring. This is talking about having

def fxn(a, (b, c), d):

    pass
Be a valid function signature. So the destructuring is held in the function definition.

Python 3 will still allow

def fxn(a, x, d):

    (b, c) = x

    pass
Both Python and ES6 JavaScript allow destructuring arrays:

//javascript

let [x, y] = [1,2]

#python

[x, y] = [1,2]

(x, y) = (1,2)

Re:Python 3.5.0 by Arnavion on Sunday September 13, 2015 @08:09PM (#10213190)
ES6 does allow that via destructuring - https://babeljs.io/repl/#?experimental=true&evaluate=true&lo...

    function fxn(a, [b, c], d) {
      console.log(a, b, c, d);
    }
Re:Python 3.5.0 by wfunction on Monday September 14, 2015 @03:33AM (#10213973)
> If you think the (rightful) removal of a hardly used feature[1] that has some big problems is a blocking issue then I feel sorry for you.

Uh, thanks?

I would call it anything but "rightful". Making life harder for introspection tools is hardly a rightful reason for removing a core language feature. The code is what most developers are trying to develop, not the introspection tools.

Re:Python 3.5.0 by orf on Monday September 14, 2015 @04:03AM (#10214036)
> Making life harder for introspection tools is hardly a rightful reason for removing a core language feature

Well that's one reason yes, and by itself not really a good enough one. But if you read the PEP there are another 4 good reasons that you omitted from your comment, why is that?

Re:Python 3.5.0 by wfunction on Monday September 14, 2015 @04:23AM (#10214086)
> Well that's one reason yes, and by itself not really a good enough one. But if you read the PEP there are another 4 good reasons that you omitted from your comment, why is that?

Because the other reasons were twice as horrible.

"No loss of abilities"? Uh, you can't do this in lambdas anymore.

"Exception to the rule"? Who cares? It was useful and readable, that's all that matters.

"Uninformative Error Messages"? This has never been a pain point for me. If you don't like it then no one forced you to use it...

"Little Usage"? Well I guess everyone matters but me. Which is fine, but then you shouldn't wonder why it would tick me off.

Re:Python 3.5.0 by lelandbatey on Sunday September 13, 2015 @05:21PM (#10212827)
As someone who's bounced back and forth between Python 2 and Python 3, I'm curious about your need of parameter tuple unpacking[0]. I've never encountered it, and after some research I don't understand the use case.

I don't mean to sound like I'm trying to belittle your position, I would like to understand more. The PEP below doesn't seem to do a very good job explaining why people like them, and I'd like to hear a proponents position on the feature.

[0] - https://www.python.org/dev/peps/pep-3113/

Re:Python 3.5.0 by wfunction on Monday September 14, 2015 @03:31AM (#10213969)
> As someone who's bounced back and forth between Python 2 and Python 3, I'm curious about your need of parameter tuple unpacking[0]. I've never encountered it, and after some research I don't understand the use case.

> I don't mean to sound like I'm trying to belittle your position, I would like to understand more. The PEP below doesn't seem to do a very good job explaining why people like them, and I'd like to hear a proponents position on the feature.

Basically, I need it for functional programming. See here:

https://news.ycombinator.com/item?id=10213963

Re:Python 3.5.0 by mycelium on Sunday September 13, 2015 @06:09PM (#10212960)
I use it like es6 or haskell destructuring. Sure it's a little weak compared to both those implementations, but the tuple case covers enough to be useful.
Re:Python 3.5.0 by pyre on Sunday September 13, 2015 @08:01PM (#10213173)
EC6 allows you to destructure in the function definition?
Re:Python 3.5.0 by mycelium on Sunday September 13, 2015 @11:58PM (#10213584)
Re:Python 3.5.0 by emidln on Monday September 14, 2015 @12:31AM (#10213644)
As someone who splits his time between Python, Clojure, and Javascript (via Babel), lack of this is extremely annoying for Python since the other two languages allow it.
Re:Python 3.5.0 by unoti on Sunday September 13, 2015 @06:07PM (#10212958)
A good example of a use case I can think of would be to pass an (x,y) coordinate pair as a single parameter, and unpack it in the parameter definition. This would save having an extra line that says (x,y) = pt.

Unless I'm missing something, I don't see this as a show stopper personally, and see it as increasing readability.

Re:Python 3.5.0 by jacobolus on Sunday September 13, 2015 @07:20PM (#10213106)
You should use a namedtuple for that sort of thing, and then refer to the members as pt.x and pt.y.
Re:Python 3.5.0 by paulsutter on Monday September 14, 2015 @01:21AM (#10213734)
At first glance, parameter tuple unpacking seems like a silly hack that was wisely removed, explained here http://legacy.python.org/dev/peps/pep-3113/

What are the cases where you use it / rely on it?

Re:Python 3.5.0 by wfunction on Monday September 14, 2015 @03:26AM (#10213963)
> What are the cases where you use it / rely on it?

Basically any time I need to unpack inside a lambda (e.g. functional programming) and have to use something like itertools.groupby(), I run into trouble with Python 3. For example:

  from itertools import groupby
  def groupby_unsorted(items, key):
    return map(lambda (g, l): (g, map(lambda (k, v): v, l)), groupby(sorted(map(lambda v: (key(v), v), items)), lambda (k, v): k))
  print(groupby_unsorted([1, 2, 3, 4], lambda v: v % 2))
Never ran into problems with it either.
Re:Python 3.5.0 by azag0 on Monday September 14, 2015 @07:04PM (#10218062)
Python has comprehensions for this style of programming:

    def groupby_unsorted(iterable, key):
        return [(k, [v for k, v in g])
                for k, g in
                groupby(sorted((key(v), v) for v in iterable),
                        lambda item: item[0])]
    print(groupby_unsorted([1, 2, 3, 4], lambda v: v % 2))
Re:Python 3.5.0 by wfunction on Tuesday September 15, 2015 @05:00PM (#10223173)
Yes, list comprehensions can take care of some of these, but you're completely missing the entire point.

The point was that writing something like

  lambda item: item[0]
in your code is inferior to

  lambda (k, v): k
in terms of readability and comprehensibility. It is both longer and it also doesn't document the fact that the item is semantically a key-value pair.

The problem is not (and has never been) whether something is "necessary" or "possible". Tuple unpacking obviously completely unnecessary to begin with, it has nothing to do with whether this is done in a parameter or not. The problem is whether the code is expressed better via unpacking.

Re:Python 3.5.0 by aldanor on Monday September 14, 2015 @04:40AM (#10214136)
But tuple unpacking inside lambdas is actually supported in Python 3, isn't it?
Re:Python 3.5.0 by wfunction on Monday September 14, 2015 @07:02AM (#10214507)
Could you give me an example of what you mean?
Re:Python 3.5.0 by jay_kyburz on Sunday September 13, 2015 @04:42PM (#10212736)
Probably means from 3rd gear down to 2nd.
Re:Python 3.5.0 by sadgit on Sunday September 13, 2015 @03:05PM (#10212440)
Care to share some highlights? Fifth to second sounds like a big difference!
Re:Python 3.5.0 by inglor on Sunday September 13, 2015 @03:42PM (#10212548)
It has the ability to statically check the type system, that's amazing. Moreover async/await with async resource management (which C# doesn't have yet) gives it a real edge for server development.
Re:Python 3.5.0 by sadgit on Sunday September 13, 2015 @07:41PM (#10213140)
> has the ability to statically check the type system

I was under the impression that type checking was not one of the goals of PEP 484 etc.

Re:Python 3.5.0 by useerup on Monday September 14, 2015 @12:48AM (#10213677)
> Moreover async/await with async resource management (which C# doesn't have yet)

In C#, the using statement combines with async/await. It is cool that Python finally gains proper async/await, there is no need to diss other languages.

Re:Python 3.5.0 by inglor on Monday September 14, 2015 @10:14AM (#10215135)
IDisposable's dispose is not an async function, there is no IAsyncDisposable interface with language support. There is however, a proposal https://github.com/dotnet/roslyn/issues/114 , I'm not dissing the language but things are the way they are.
Re:Python 3.5.0 by ColinDabritz on Sunday September 13, 2015 @03:52PM (#10212584)
What is async resource management? can you link to docs for the features you mean? I'm having trouble googling this one, maybe different keywords are used?
Re:Python 3.5.0 by 1st1 on Sunday September 13, 2015 @04:18PM (#10212679)
I think inglor refers to the new 'async with' statement: https://docs.python.org/3/reference/compound_stmts.html#asyn...

Using it you can safely cleanup/commit transaction/release lock/etc when exiting a block of statements (even if an exception was raised). Plain 'with' statement cannot call asynchronous code in '__exit__' methods, 'async with' can do that (in '__aexit__').

Re:Python 3.5.0 by jodah on Monday September 14, 2015 @01:29PM (#10216225)
> async/await with async resource management (which C# doesn't have yet) gives it a real edge for server development

An edge over what? You're still limited to a single thread via the GIL. Until that problem is solved, Python is certainly not the best bet (all else aside) for server development.

Re:Python 3.5.0 by cben on Saturday September 19, 2015 @05:31PM (#10245599)
Node.js is also single thread and has been doing fine on servers.

Do you really need to share mutable state between threads in your server? If yes, what's your story when you'll need to scale to multiple servers?

If not because you can keep shared mutable state in a separate service (DB or similar), you can deal with one-machine scaling very similarly to scaling across machines - just start/fork a process per CPU. You get simplicity, avoid the whole thread-safety can of bugs, and all the administration benefits of stateless servers.