Issue
Suppose I create a class with a static method and want to run that method from another classes method or script function.
What is the scope of the static method?
ex:
def Class myClass:
@staticmethod
def mystaticmethod(input):
print("blah")
def scriptfunc():
myClass.mystaticmethod()
Is this valid?
Solution
What you have is valid.
But too elaborate on the purpose of @staticmethod
, here's Short answer:
Declaring a @staticmethod
would mean 2 things:
- You don't care about the properties or attributes of a method as it's independent of other classes,
- You do not require creating an
__init__
or a super method to override it's content or attributes, and doesn't require a subclass/parent class to handle itself.
Answered By - de_classified
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.