modeler: __getattr__ for modules

Wiktor Sadowski art at wiktorsadowski.com
Sun Jun 22 01:15:00 CEST 2003


Some people have been asking for modeler.pyd for Python2.3.
It's available now at: http://www.wiktorsadowski.com/Python

Wiktor  

modeler
======
Modeler enables dynamic module-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.

More details and windows binaries for  Python2.2 , Python2.3
can be found at:
http://www.wiktorsadowski.com/Python

Examples of simple module-class-factory and importing two or more modules
from one dll : 
http://www.wiktorsadowski.com/Python/modsample.html

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

Have fun,
Wiktor Sadowski


add to site.py:
import modeler
===========

dynmod.py
==========
def __getattr__(thismod,name):
        if name in thismod.__dict__.keys():
                return thismod.__dict__[name]
        else:
           # in more useful cases:
           #thismod.__dict__[name]=anAttr
           #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
>>> dynmod.foo
'Default Attr'
>>> dynmod.spam
'Default Attr'
>>> 







More information about the Python-list mailing list