静态方法 - 如何从另一个方法调用一个方法? [英] Static methods - How to call a method from another method?

查看:45
本文介绍了静态方法 - 如何从另一个方法调用一个方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我有调用类中另一个方法的常规方法时,我必须这样做

When I have regular methods for calling another method in a class, I have to do this

class test:
    def __init__(self):
        pass
    def dosomething(self):
        print "do something"
        self.dosomethingelse()
    def dosomethingelse(self):
        print "do something else"

但是当我有静态方法时我不能写

but when I have static methods I can't write

self.dosomethingelse()

因为没有实例.在 Python 中从同一个类的另一个静态方法调用一个静态方法需要做什么?

because there is no instance. What do I have to do in Python for calling an static method from another static method of the same class?

推荐答案

class.method 应该可以工作.

class SomeClass:
  @classmethod
  def some_class_method(cls):
    pass

  @staticmethod
  def some_static_method():
    pass

SomeClass.some_class_method()
SomeClass.some_static_method()

这篇关于静态方法 - 如何从另一个方法调用一个方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆