> def new(request, errors = [], messages = []):
> ...
> [ snip]
> unfortunatly, django somehow remembers this and the arrays don't get cleaned
> up.
It's not django that's tripping you up.
> So, normal python rules say these should get default values [] and
> thus be cleared.
Actually, normal python rules say "Don't do this." It is (IMHO) one
of the less intuitive aspects of the language -- it's consistent, just
not intuitive. If the default value for a parameter is mutable (in
this case, a list) then what happens is that each time the function is
called without that param, then it *uses the same mutable object* for
the default value. This is why it has "memory".
Instead, set the params to None and test for that in the function.
E.g.
def new(request, errors = None, messages = None):
if errors is None:
errors = []
if messages is None:
messages = []
...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---