Skip to content
Advertisement

Tag: class-method

What are “inheritable alternative constructors”?

I stumbled over the term “inheritable alternative constructors” in this answer: https://stackoverflow.com/a/1669524/633961 The link points to a place where classmethod gets explained. Do other programming languages have this feature, too? Answer One of the things that you can do with ANY language that has class methods (or similar) is provide alternative constructors. A slightly contrived Python3 example below : with

What’s an example use case for a Python classmethod?

I’ve read What are Class methods in Python for? but the examples in that post are complex. I am looking for a clear, simple, bare-bones example of a particular use case for classmethods in Python. Can you name a small, specific example use case where a Python classmethod would be the right tool for the job? Answer Helper methods for

__getattr__ for static/class variables

I have a class like: Whenever MyClass.Foo or MyClass.Bar is invoked, I need a custom method to be invoked before the value is returned. Is it possible in Python? I know it is possible if I create an instance of the class and I can define my own __getattr__ method. But my scnenario involves using this class as such without

Advertisement