Creating a cell 'by hand'

Jean-Paul Calderone exarkun at
Fri Nov 9 01:08:20 CET 2007

On Thu, 8 Nov 2007 18:30:15 -0500, "Prepscius, Colin \(IT\)" <colin.prepscius at> wrote:
>The last argument to new.function takes a closure, which is a tuple of
>cell objects.  Does anybody know how to create those cell objects 'by

Here's one approach:

    >>> def f():
    ...     x = 10
    ...     def g():
    ...             a = x
    ...     return g
    >>> f().func_closure
    (<cell at 0xb7d47494: int object at 0x8141d44>,)

I don't know what your use-case is, so I have no idea if this is the
kind of solution you're looking for.


More information about the Python-list mailing list