if there is a static method inside a class. Then say I have another method within the same class which happens to be a classmethod. Now if I am calling the static method from my classmethod why do I have to qualify the static method with a cls.<staticmethod name> syntax? let me give an example for clarity: say I have a class A: class A: @staticmethod def s_method(): print("this is static method message") @classmethod def c_method(cls): cls.s_method() print("this is class method message") my question is why do I have to qualify the s_method() with a "cls" prefix, eventhough I am calling it from the same class?
Comment
if there is a static method inside a class. Then say I have another method within the same class which happens to be a classmethod. Now if I am calling the static method from my classmethod why do I have to qualify the static method with a cls.<staticmethod name> syntax?
let me give an example for clarity: say I have a class A:
class A:
@staticmethod
def s_method():
print("this is static method message")
@classmethod
def c_method(cls):
cls.s_method()
print("this is class method message")
my question is why do I have to qualify the s_method() with a "cls" prefix, eventhough I am calling it from the same class?
Replies
Do you refer to the line `cls.s_method()`? Are you asking why you can't write `s_method()`?