__getattr__ equivalent for a module
Maksim Kasimov
maksim.kasimov at gmail.com
Mon Jan 15 12:14:14 EST 2007
More information about the Python-list mailing list
Mon Jan 15 12:14:14 EST 2007
- Previous message (by thread): __getattr__ equivalent for a module
- Next message (by thread): catching signals in an object
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi Leif, many thanks - it works Leif K-Brooks wrote: > Maksim Kasimov wrote: >> so my question is: how to tune up a module get default attribute if we >> try to get access to not actually exists attribute of a module? > > You could wrap it in an object, but that's a bit of a hack. > > import sys > > class Foo(object): > def __init__(self, wrapped): > self.wrapped = wrapped > > def __getattr__(self, name): > try: > return getattr(self.wrapped, name) > except AttributeError: > return 'default' > > sys.modules[__name__] = Foo(sys.modules[__name__]) -- Maksim Kasimov
- Previous message (by thread): __getattr__ equivalent for a module
- Next message (by thread): catching signals in an object
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list