Live data from Hacker News

What’s New in Python 3.0

docs.python.org

31–40 of 43 posts

Re: What’s New in Python 3.0

#31
post #24

Earlier quoted context omitted.

what does a real one consitute of? and why do you want that? i use pyhton as a superb general-purpose language and for gluing together a lot of different parts of software/programs. for that purpose, simplicity and readability is essential.

Sometimes, I just want to pass a function to a function. And sometimes, I want to just say, very concisely, "do this", without giving a name to "this".

But you can do that in both python 3 and 2.5...

Re: What’s New in Python 3.0

#33
post #31
post #24

Earlier quoted context omitted.

Sometimes, I just want to pass a function to a function. And sometimes, I want to just say, very concisely, "do this", without giving a name to "this".

But you can do that in both python 3 and 2.5...

Maybe he's talking about

    >>> funcs = []
    >>> for x in xrange(3):
    >>>   funcs.append(lambda: x)
    >>> sum(f() for f in funcs)
    6
Were you expecting 3? Lambdas (besides having such an awfully long and difficult to type name :P) capture only the "name" of x, so when the for loop changes x later, the lambda sees the new value--so the sum is (2 + 2 + 2) instead of (1 + 2 + 3).

What you can do, instead (and I do it often enough that I wish lambdas created their own lexical closure....)

    >>> funcs = []
    >>> for x in xrange(3):
    >>>   funcs.append(lambda x=x: x)
    >>> sum(f() for f in funcs)
    3
By using x as a default argument, you force the x inside the lambda to be the value it was when the lambda was created. It kinda sucks, and always felt to me like a deficiency of the implementation leaking up into the language :[

Re: What’s New in Python 3.0

#34
post #31

Earlier quoted context omitted.

But you can do that in both python 3 and 2.5...

Maybe he's talking about >>> funcs = [] >>> for x in xrange(3): >>> funcs.append(lambda: x) >>> sum(f() for f in funcs) 6 Were you expecting 3? Lambdas (besides having such an awfully long and difficult to type name :P) capture only the "name" of x, so when the for loop changes x later, the lambda sees the new value--so the sum is (2 + 2 + 2) instead of (1 + 2 + 3). What you can do, instead (and I do it often enough…

I think you mean "2 + 2 + 2 instead of 0 + 1 + 2"

Re: What’s New in Python 3.0

#35
post #4
post #3

print("fatal error", file=sys.stderr) So, Python has become even less succinct for the sake of "consistency". I think there is only one flawless, absolutely consistent machine, and that's Turing machine. The urge for consistency and simplification (I mean, if you are consistent in your aspiration for consistency) inevitably leads to reinventing the Turing machine in its purity. It's OK, except for some reason nobody…

print >>sys.stderr, "fatal error" Considering this is this old version of what you copied, I don't think anything has been lost...

sys.stderr.write("fatal error\n")

Re: What’s New in Python 3.0

#36
post #30
post #29

Earlier quoted context omitted.

> you are not supposed to do this, says Python to you, because it's a bad practice and can lead to errors. Isn't that one of the main themes of Python? That you can expect another programmer to have solved the same problem almost the same way..? I figure this is how that happens.

Curiously, this approach is usually welcomed in corporate environments. Java and C# are on the same shelf in this regard. It limits creativity by leaving no doors for new ways of doing things. Certain class of programmers just can't bear when they are told what's right and what's wrong in programming.

Java, especially if you get into the OOP patterns fun, can present a million ways of doing things. Java is terrible about this.

Re: What’s New in Python 3.0

#38
post #26

WTF? Why doesn't the new repr(1L) return "1L"? I thought the whole point of the repr custom was to output something that would regenerate the same object. Are they going to abandon the 'Format %d:%s" % (n, s)' or just add PEP 3101? The % syntax is down-and-dirty practical good. PEP 3101 is neat, but printf() syntax is tough to beat. OK, the first screenful or so scared me. The rest looks like clear-cut improvements.…

WTF? Why doesn't the new repr(1L) return "1L"? I thought the whole point of the repr custom was to output something that would regenerate the same object. Because there's no such thing as 1L anymore. There is one unified (unbounded) integer, and I believe the C implementation will use int to represent small values and long when necessary (and list of long beyond that?). Are they going to abandon the 'Format %d:%s" %…

Muchas gracias for the explanation of repr. I knew I shouldn't have lost faith in Guido.

The ctemplate sounds really frickin' interesting. Is this an easy way to get a major performance boost on CPU-intensive bits of Python? Actually, this is probably getting off-topic, but will you email me when ctemplate is ready for prime-time?

Re: What’s New in Python 3.0

#39
post #28

I hate the new print(x) changes in Python. Dammit! I loved typing print x.

I'm worried about the hassle as every 'hello world' tutorial stops working. The change has been on the cards for yonks, and the print('foo') version has always been valid - why hasn't there been a push to get the documentation changed before introducing the change?

Re: What’s New in Python 3.0

#40
post #38

Earlier quoted context omitted.

WTF? Why doesn't the new repr(1L) return "1L"? I thought the whole point of the repr custom was to output something that would regenerate the same object. Because there's no such thing as 1L anymore. There is one unified (unbounded) integer, and I believe the C implementation will use int to represent small values and long when necessary (and list of long beyond that?). Are they going to abandon the 'Format %d:%s" %…

Muchas gracias for the explanation of repr. I knew I shouldn't have lost faith in Guido. The ctemplate sounds really frickin' interesting. Is this an easy way to get a major performance boost on CPU-intensive bits of Python? Actually, this is probably getting off-topic, but will you email me when ctemplate is ready for prime-time?

No, although it could potentially be modified to fulfill that purpose. Its purpose is best described as providing a macro system that allows some C code to be generated by more-succinct Python code.

By the way, you e-mail is not in your profile. You can send me an e-mail (in my profile), and I'd be happy to keep you posted.

Post reply on HN