__call__ in module?
Leif K-Brooks
eurleif at ecritters.biz
Tue Sep 27 19:34:27 EDT 2005
ncf wrote:
> I have a feeling that this is highly unlikely, but does anyone in here
> know if it's possible to directly call a module, or will I have to wrap
> it up in a class?
You could use trickery with sys.modules to automatically wrap it in a class:
import sys
from types import ModuleType
class CallableModule(ModuleType):
def __call__(self):
print "You called me!"
mod = FooModule(__name__, __doc__)
mod.__dict__.update(globals())
sys.modules[__name__] = mod
More information about the Python-list
mailing list