M
Maksim Kasimov
Hi,
in any python class it is possible to define __getattr__ method so that if we try to get some value of not actually exists instance attribute, we can get some default value.
For example:
class MyClass:
def __getattr__(self, attname):
if attname.startswith('a'):
return "*"
i = MyClass()
....
i.aValue # it gives "*" if "i.aValue" will not be set before this call
i need to define the same behavior for a module:
import mymodule
mymodule.anyattribute
or
from mymodule import anyattribute
"anyattribute" is not actually defined in the module, but gives some attribute of the module
so my question is: how to tune up a module get default attribute if we try to get access to not actually exists attribute of a module?
(python 2.4 or 2.2)
many thanks for help.
in any python class it is possible to define __getattr__ method so that if we try to get some value of not actually exists instance attribute, we can get some default value.
For example:
class MyClass:
def __getattr__(self, attname):
if attname.startswith('a'):
return "*"
i = MyClass()
....
i.aValue # it gives "*" if "i.aValue" will not be set before this call
i need to define the same behavior for a module:
import mymodule
mymodule.anyattribute
or
from mymodule import anyattribute
"anyattribute" is not actually defined in the module, but gives some attribute of the module
so my question is: how to tune up a module get default attribute if we try to get access to not actually exists attribute of a module?
(python 2.4 or 2.2)
many thanks for help.