I want to do something like the following
class A:
def static_method_A():
print "hello"
def main(param=A):
param.static_method_A()
I want this to be equivalent to A.static_method(). Is this possible?
I want to do something like the following
class A:
def static_method_A():
print "hello"
def main(param=A):
param.static_method_A()
I want this to be equivalent to A.static_method(). Is this possible?
Sure. Classes are first-class objects in Python.
Although, in your example, you should use the @classmethod
(class object as initial argument) or @staticmethod
(no initial argument) decorator for your method.
Sure why not? Don't forget to add @staticmethod to static methods.
class A:
@staticmethod
def static_method_A():
print "hello"
def main(param=A):
param.static_method_A()
You should be able to do the following (note the @staticmethod
decorator):
class A:
@staticmethod
def static_method_A():
print "hello"
def main(param=A):
param.static_method_A()