namespaces
Simon Burton
simon at arrowtheory.com
Tue Aug 9 23:50:26 EDT 2005
I've been needing a module level __getattr__ for some c library
wrapping. This has solved the problem:
# mymod.py:
import sys
from new import module
class ModuleProxy(module):
def __init__( self, name, master ):
module.__init__( self, name )
self._master = master
self.__dict__["__all__"] = dir(master)
def __getattr__(self, name):
attr = getattr( self._master, name )
return attr
# ... end of file:
sys.modules["mymod"] = ModuleProxy("mymod",sys.modules["mymod"])
--Simon Burton
More information about the Python-list
mailing list