3 ms·
Really? Python's handling of reaching into the outer scope of a function is just as confusing (although I hear it is fixed in 3000?). Python used to be my favo
by mistercow 14y ago
Really? Python's handling of reaching into the outer scope of a function is just as confusing (although I hear it is fixed in 3000?).
Python used to be my favorite language, but I'm currently working on a project that is CoffeeScript on the client and Python on the server, so I'm getting plenty of time to compare them side by side. It would be difficult to overstate how much I prefer working with CoffeeScript.
The thing is, this scope situation, which is admittedly not as elegant as it could be, is really a rare situation to run into. If it happens to you often, it generally means that you need to give your more global variables less vague names.
- jrockway 14y agoReally? Python's handling of reaching into the outer scope of a function is just as confusing (although I hear it is fixed in 3000?) Do you mean: try: foo = '42' except Whatever: raise print "foo is %s" % foo If so, I really like that feature. It's much clearer to me than what I'd write in another language: foo = None try: foo = 42 ...
- ostso 14y agoPerhaps mistercow means things like def foo(): x = 5 def bar(): print x def baz(): x = 6 print x bar() baz() print x Which prints 5, 6, 5. If baz tried to print x before assigning, it would be an UnboundLocalError.
- lvh 14y agoI believe you are referring to the nonlocal keyword, which means that unlike the regular case (assignment binds as locally as possible), assignment will bind where the name is bound now. (There's a third case for globals, but let's not talk about those.)