Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Anti-Patterns in Python Programming. Parent comment
More specifically, given a better 'default arguments thing', how would you interpret:
x = [2] def f(x=x*5): x.append(4)
x = [2] def f(x=DefaultArg): if x is DefaultArg: x = x*5 x.append(4)
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)
What other solution are you thinking of?
More specifically, given a better 'default arguments thing', how would you interpret:
With the earlier conversion it's: 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:
then you'll get "SyntaxError: name 'x' is parameter and nonlocal".What other solution are you thinking of?