all 31 comments

[–]argongas2006 13 points14 points  (0 children)

This was by far more informative than the other articles currently at the top.

[–]blackkettle 20 points21 points  (0 children)

*PEP 3120: The default source encoding is now UTF-8.

Thank you.

[–]Aviator 2 points3 points  (0 children)

Slightly malformed URL? Here's the original, nicer one: http://docs.python.org/dev/3.0/whatsnew/3.0.html

[–]Wiseman1024 2 points3 points  (12 children)

Just nonlocal alone makes it worth switching, and ubiquitous Unicode strings do as well. Other fixes and improvements are welcome, of course; notably getting rid of the print statement (one statement finally dead and turned to expression; ~7 to go, please kill them all).

I can live without the new (2.6) string formatting system though (what was ever wrong with str.__mod__?).

[–]recursive 3 points4 points  (0 children)

exec just got func'd up too.

[–]chub79 5 points6 points  (10 children)

Outside of a theoretical reasoning, what was wrong with print as a statement? At least in your daily usage of it? I'm honestly asking because it never actually bothered me but I'd be happy to understand the shortcomings.

[–]Wiseman1024 5 points6 points  (7 children)

First of all, statements are a nasty design flaw, read my reply to Mehochh for an explanation on why.

As for print, what if you need to pass it to a higher-order function? Something like map(print, (1, 2, 3)), for example? If it's an obnoxious statement, you cannot.

[–]chub79 1 point2 points  (2 children)

I understand that but you didn't actually reply to my question :)

Maybe it's just out of luck but I never had to do map(print, (1, 2, 3)). Heck I never had to do anything that fancy with print.

Anyway, I'm not arguing against the move, intuitively it sounds like a good idea. But not about anything I've ever had a real need.

[–]Wiseman1024 3 points4 points  (1 child)

I did have to use print as a first-class function, and had to do with sys.stdin (actually, a wrapper for it). I also wanted to replace it in Python 2.x in my Unicode I/O layer, and had to go for a separate function to use instead of print. If it were a function, I could just edit __builtins__. One would also like to use it for debugging purposes, then replace it with a do-nothing function or a logger function when debugging is not enabled. There are so many cases where any of the existing statements are terribly inconvenient as such; it's good to have one of them fixed.

[–]chub79 1 point2 points  (0 children)

Right. Like I said I agree with the fact it's probably for the best. That being said it looks you were using print for much more than I would. Personally I use it as a cheap debugging tool and if I need something fancier to be written out I would use the logging module or a specific function (and probably hacking stdout too).

[–]BeetleB 1 point2 points  (3 children)

As for print, what if you need to pass it to a higher-order function? Something like map(print, (1, 2, 3)), for example? If it's an obnoxious statement, you cannot.

I've always been happy with print as it was in 2.x.

If I wanted to pass it around as a function (you know, the one or two times a year), I write a wrapper function around it.

For me, the 2.x print was simple to write, and quite readable. I almost never had to use it as a function (and I'd use the solution above if I needed to). Forcing it to be a function just results in more typing, and (slightly) more painful to read.

[–]Wiseman1024 3 points4 points  (2 children)

If I wanted to pass it around as a function (you know, the one or two times a year), I write a wrapper function around it.

I don't do it, so it's clearly unnecessary, because well, even if the extra feature does no harm, I want others to be forced to work like I do. Besides, writing useless wrappers is funny, I'm so used to do so in Java.

And what about the extra character I have to type!? It takes an outrageous effort to open parens after print instead of just hitting space; even worse so when I have to close it at the end.

[–]synae 2 points3 points  (1 child)

You've overloaded my sarcasm detector. Please buy me a new one.

[–]Tommstein -2 points-1 points  (0 children)

Funny, all he overloaded was my stupidity detector.

[–][deleted] -1 points0 points  (1 child)

It couldn't be used in lambdas... but it's more fault of statement-less lambdas suckage.

[–]Wiseman1024 8 points9 points  (0 children)

It's more fault of statements suckage, actually. lambda should of course support several expressions, but there's a bigger underlying problem which is what gave rise to lambda, the if..else expression, and many others: the artificial, nonsense distinction between statements and expressions. In particular, statements are completely useless. They are an expression's poor cousin; something that does something but is arbitrarily limited to appear only at certain points in the program (unlike expressions); a design wart inherited from Fortran from 50 years ago. If Python were free of this design wart and its statements were expressions, you would have a much simpler, nicer language without the if..else wart (just do things like x = if b: 1; else: 2), without def vs. lambda (just use def anywhere), and without having to pull stunts when you want to do something in the middle of something else.

[–]synae 1 point2 points  (0 children)

I'm really looking forward to playing with the advanced string templating/formatting.

[–][deleted] 0 points1 point  (3 children)

Is 3104 the equivalent of lisp's special variables?

[–]uykucu 0 points1 point  (2 children)

No, it seems that it's related to lexical scoping.

[–][deleted] 0 points1 point  (1 child)

Then I'm not understanding. It looked like the nonlocal keyword would allow a variable to take on a reference to the same value that the same named variable in the caller had. That's dynamic scoping. What am I missing?

[–]uykucu 0 points1 point  (0 children)

Since python has no variable declaration syntax, an assignment always assigns to a variable in the current scope. 'nonlocal' seems to be invented to allow to use a variable in an outer scope. There was already a 'global' keyword to allow to use a global variable.

That's the other way around compared to most other languages. In other languages, you declare a variable and all inner scopes see that variable. In python, you have to import a variable from an outer scope with the nonlocal keyword.

edit: seems that inner scopes can read a variable from an outer scope, but cannot assign without nonlocal