3 ms·
In Python 3 there's the nonlocal keyword to deal with the scoping thing. The default arguments thing is worse than a lot of the stuff Python 3 corrected.
by syllogism 12y ago
In Python 3 there's the nonlocal keyword to deal with the scoping thing.
The default arguments thing is worse than a lot of the stuff Python 3 corrected.
- dalke 12y agoI don't see how nonlocal could fix this. Could you explain? More specifically, given a better 'default arguments thing', how would you interpret: x = [2] def f(x=x*5): x.append(4) With the earlier conversion it's: x = [2] def f(x=DefaultArg): if x is DefaultArg: x = x*5 x.append(4) This isn't going to work because the x inside of f() is different than the outside x, and you'll get the error message I mentioned. If you add a nonlocal, as in: x = [2] def f(x=DefaultArg): nonlocal x if x is DefaultArg: x = x*5 x.append(4) then you'll get "SyntaxError: name 'x' is parameter and nonlocal". What other solution are you thinking of?
- syllogism 12y agoAh I see. Yeah nonlocal can't fix that.