ANN:modeler __getattr__ for modules 
Author Message
 ANN:modeler __getattr__ for modules

modeler
======

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:
http://www.*-*-*.com/

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

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
===========

dynmodule.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.

Quote:
>>> from dynmod import whatever1,whatever2
>>> whatever1
'Default Attr'
>>> whatever2
'Default Attr'
>>> import dynmod
>>> dynmod.foo
'Default Attr'
>>> dynmod.spam
'Default Attr'



Tue, 06 Dec 2005 13:09:25 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. modeler: __getattr__ for modules

2. Checking for attribute in the current module with getattr( )

3. Is there a module __getattr__ function?

4. Modules with __getattr__ (Re: PEP 317: Eliminate Implicit Exc eption Instantiation)

5. __getattr__ functionality for modules?

6. ANN: Jestur 0.2b gesture recognition module

7. ANN: path module 1.1.3

8. ANN: Python Spread Module 1.3 Released

9. ANN: Logging Module v0.4.6 released

10. ANN: Logging Module v0.4.5 released

11. ANN: set-0.1 module available

12. ANN: Logging Module v0.4.4 released

 

 
Powered by phpBB® Forum Software