Is classless worth consideration
Michele Simionato
michele.simionato at poste.it
Thu Apr 29 08:34:11 EDT 2004
Michael <mogmios at mlug.missouri.edu> wrote in message news:<mailman.104.1083210274.25742.python-list at python.org>...
> Is there any way to to call a class method without making an instance of
> that class?
Yes, with classmethods and staticmethods and more in general with
custom descriptors.
> To me that would be useful because you could mimic modules
> without having to create a sepperate file. Or is there already a way to
> do that?
You can dynamically generate a module:
>>> from types import ModuleType # in Python 2.3
>>> mymodule=ModuleType("mymodule","This a dynamic module")
>>> help(mymodule)
Help on module mymodule:
NAME
mymodule - This a dynamic module
FILE
(built-in)
You can populate the module with setattr or by hand:
>>> mymodule.a=1
>>> mymodule.a
1
HTH,
Michele Simionato
More information about the Python-list
mailing list