0

Say, the code is

class A():
    @staticmethod
    getB():
        return ['B', 'BB']

    list_B = A.getB()

How would I access function B() within the class that's outside of any function? In the code snippet, A isn't being recognized as a valid variable/class.

Mr. Sigma.
  • 405
  • 1
  • 4
  • 15

1 Answers1

1

You have 2 possibilities :

  • use getB.__func__()
  • use A.getB() in another function within the class

Try this :

class A():
    @staticmethod
    def getB():
        return ['B', 'BB']

    list_B = getB.__func__()
    print("list_B_1", list_B)

    def foobar(self):
        list_B_2 = A.getB()
        print("list_B_2", list_B_2)

a = A()
a.foobar()
Phoenixo
  • 2,071
  • 1
  • 6
  • 13