If a class Child inherits from Parent, how to implement Child.some_method if Parent.some_method() returns Parent instance ?

Christian Heimes lists at cheimes.de
Thu Oct 29 19:07:35 EDT 2009


metal wrote:
> But this style makes code full with ugly  self.__class__
> 
> Any standard/pythonic way out there?

You are already using one standard way to implement an alternative
constructor.

If you don't need any instance attributes you can use another way:

class Egg(object):
    @classmethod
    def spam(cls):
        return cls(...)

Christian




More information about the Python-list mailing list