__getattr__ for static/class variables
__getattr__() and __str__() for an object are found on its class, so if you want to customize those things for a class, you need the class-of-a-class. A metaclass. class FooType(type): def _foo_func(cls): return ‘foo!’ def _bar_func(cls): return ‘bar!’ def __getattr__(cls, key): if key == ‘Foo’: return cls._foo_func() elif key == ‘Bar’: return cls._bar_func() raise AttributeError(key) … Read more