free variables /cell objects question
duncan.booth at invalid.invalid
Tue Jan 23 13:11:31 CET 2007
"gangesmaster" <tomerfiliba at gmail.com> wrote:
> what problem does the cell object solve?
The closure represents the variable, not the object. So if x is rebound to
a different object your inner function g() will now access the new object.
If the object itself was passed to MAKE_CLOSURE then g would only ever see
the value of x from the instant when g was defined.
>>> def f(x):
print "x is", x
x += 1
x is 1
x is 2
More information about the Python-list