Jes*_*ieh 6 python parameters static
我想做类似以下的事情
class A:
def static_method_A():
print "hello"
def main(param=A):
param.static_method_A()
Run Code Online (Sandbox Code Playgroud)
我希望这相当于A.static_method().这可能吗?
当然.类是Python中的第一类对象.
虽然,在您的示例中,您应该为您的方法使用@classmethod(类对象作为初始参数)或@staticmethod(无初始参数)装饰器.
您应该能够执行以下操作(请注意@staticmethod装饰器):
class A:
@staticmethod
def static_method_A():
print "hello"
def main(param=A):
param.static_method_A()
Run Code Online (Sandbox Code Playgroud)