Call method from string

前端 未结 4 1229
不思量自难忘°
不思量自难忘° 2020-12-28 12:27

If I have a Python class, and would like to call a function from it depending on a variable, how would I do so? I imagined following could do it:

class CallM         


        
4条回答
  •  一整个雨季
    2020-12-28 13:00

    Your code does not look like python, may be you want to do like this?

    class CallMe:
    
        def App(self): #// Method one
            print "hello"
    
        def Foo(self): #// Method two
            return None
    
        variable = App #// Method to call
    
    CallMe().variable() #// Calling App()
    

提交回复
热议问题