You should use @classmethod
:
@classmethod
def show(cls, message):
print("The message is: {}".format(message))
The difference between a classmethod
and a staticmethod
is that the latter knows nothing about its enclosing class, whereas the former does (via the cls
argument). A staticmethod
can just as easily be declared outside the class.
If you don’t want show()
to know anything about C
, either use @staticmethod
or declare show()
outside of C
.
6
solved Imitating a static method [duplicate]