On Wed, Mar 26, 2014 at 5:53 PM, Anthony <lifesillusion@gmail.com> wrote:
> I've yet to test it but I read a few people stating to use lambdas
> variables/properties. Is it definitely the case that it will only evaluate
> once?
from the python docs (2.7):
Default parameter values are evaluated when the function definition is
executed. This means that the expression is evaluated once, when the
function is defined, and that the same "pre-computed" value is used
for each call. This is especially important to understand when a
default parameter is a mutable object, such as a list or a dictionary:
if the function modifies the object (e.g. by appending an item to a
list), the default value is in effect modified. This is generally not
what was intended. A way around this is to use None as the default,
and explicitly test for it in the body of the function.
--
Javier
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFkDaoQimq3%2B6b4mpT3qdWvP%3DfgDM9STEcLLdN3mx1MHTRaGkQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment