python: how to refer to the class from within it ( like the recursive function)

后端 未结 13 1776
旧时难觅i
旧时难觅i 2020-12-10 10:10

For a recursive function we can do:

def f(i):
  if i<0: return
  print i
  f(i-1)

f(10)

However is there a way to do the following thin

13条回答
  •  粉色の甜心
    2020-12-10 10:53

    Maybe you could try calling __class__. Right now I'm writing a code that calls a class method from within the same class. It is working well so far.

    I'm creating the class methods using something like:

    @classmethod
        def my_class_method(cls):
           return None
    

    And calling then by using:

    x = __class__.my_class_method()
    

提交回复
热议问题