calling one staticmethod from another

Ian Kelly ian.g.kelly at gmail.com
Tue Oct 30 11:27:20 EDT 2012


On Tue, Oct 30, 2012 at 7:41 AM, Ethan Furman <ethan at stoneleaf.us> wrote:
> class Spam():
>     @staticmethod
>     def green():
>         print('on a train!')
>     @staticmethod
>     def question():
>         print('would you, could you', end='')
>         Spam.green()
>
> It can be a pain if you change the class name, but it is certainly one way
> to do it.

It fails if the staticmethod being called has been overridden in a
subclass, though.  I think the only correct way to do it with
inheritance is by replacing it with a classmethod, as the OP
suggested.



More information about the Python-list mailing list