Re:Anti-Patterns in Python Programming
by ryangittins on Wednesday July 09, 2014 @10:50AM
(#8009885)
Yes, that's correct. The default value is only interpreted once, when the `def` statement is called. After that point, it's completely mutable. You have to see Python functions as objects and default parameter values as object variables.
[ Parent
| on HN ]
Re:Anti-Patterns in Python Programming
by Dylan16807 on Wednesday July 09, 2014 @03:42PM
(#8011810)
The problem is not the existence of the object variables, but that they are in such an unfortunate place. The rest of the parameter list is declaring fresh local variables. It's inconsistent that the left side of the equals sign is per-invocation, and the right side is per-def.