cell object dereferencing

Terry Reedy tjreedy at udel.edu
Tue Dec 9 19:59:01 CET 2003

"Jan Decaluwe" <jan at jandecaluwe.com> wrote in message
news:3FD5FD4A.9060406 at jandecaluwe.com...
> Is there a way to dereference a cell object (that is, get
> the object that it references to) in Python?

[Background: a cell is an undefined internal implementation object used to
make nested scoping work as advertised.  One might think of it as a means
for persisting cross-scope name-binding of objects in intermediate nested
scopes of nested functions.  Alternatively, a cell is 'persistent read-only
shadow of an outer local'.  For nested functions that access intermediate
locals, .func_closure is a tuple of 'cells'.]

Yes and no, depending on what you mean be 'dereference'.  Within the nested
function, you 'dereference' the variable the same way you do any bound
ame  -- write it!  Outside the function, where the variable has no
conceptual existence, you can grab a cell from the func_closure tuple, but I
know of no way to access its value. Both repr() and str() return a <cell at
xxx: type at yyy> description. If you want a globally accessible value, use
a global variable.

Terry J. Reedy

More information about the Python-list mailing list