Where does a class closure live?

G

Gerard Brunick

Consider:

### Function closure example

def outer(s):
.... def inner():
.... print s
.... return inner
....['__call__', '__class__', '__delattr__', '__dict__', '__doc__',
'__get__', '__getattribute__', '__hash__', '__init__', '__module__',
'__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
'__setattr__', '__str__', 'func_closure', 'func_code', 'func_defaults',
'func_dict', 'func_doc', 'func_globals', 'func_name']

### Class instance closure example
.... class Inner(object):
.... def __call__(self):
.... print s
.... return Inner()
....['__call__', '__class__', '__delattr__', '__dict__', '__doc__',
'__getattribute__', '__hash__', '__init__', '__module__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__',
'__weakref__']

##### Class closure example
.... class Inner(object):
.... def __call__(self):
.... print s
.... return Inner
....['__call__', '__class__', '__delattr__', '__dict__', '__doc__',
'__getattribute__', '__hash__', '__init__', '__module__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__',
'__weakref__']


Now the closure for the function live in func_name. I've even done the
exercise where I build a dummy inner function that returns its closed
variable, so that I can use that thing to reach through "cells" and
check out the variables living in the closure object. Where are the
closure variables for the class instance, and the class? Can I get my
hands on them in Python?
-Gerard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top