Magic Module Methods?
Magnus Lie Hetland
mlh at idi.ntnu.no
Sat Oct 20 16:30:08 EDT 2001
I just found myself needing (or wanting) a module which
could have default values for variables that weren't set;
this can be done with Alex's object-as-module trick, but
it occurred to me, why should this be necessary? All I
wanted was to add a __getattr__ method to the module...
Why should I have to replace the module with some other
object to do that? Can't modules be more like objects in
this respect? I mean, why not simply allow this:
def __getattr__(self, name):
print 'Accessing attribute %s of module %s' (name, self)
Just a thought...
--
Magnus Lie Hetland http://www.hetland.org
"Reality is that which, when you stop believing in
it, doesn't go away." -- Philip K. Dick
More information about the Python-list
mailing list