ANN:modeler __getattr__ for modules

Wiktor Sadowski Wiktor Sadowski" <
Fri, 20 Jun 2003 07:09:25 +0200


Some posts on class-like attribute access for modules 
encourged me to get some code from my not-yet-released viz module 
and make it available as a standalone Python C extension module.

Modeler enables dynamic attribute creation/access by simply adding
a __gettattr__ function to a module. Modeler doesn't replace modules
with class instances,actually it doesn't make any changes to modules.

Some more details and modeler.pyd for Python2.2
can be found at:

Examples of simple module-class-factory and importing two or more modules
from one dll :

As for the source code:
I will try to make it available later this month.

Have fun,
Wiktor Sadowski

add to
import modeler
def __getattr__(thismod,name):
        if name in thismod.__dict__.keys():
                return thismod.__dict__[name]
           # in more useful cases:
           #return anAttr 
           return "Default Attr"
Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> from dynmod import whatever1,whatever2
>>> whatever1
'Default Attr'
>>> whatever2
'Default Attr'
>>> import dynmod
'Default Attr'
>>> dynmod.spam
'Default Attr'