Generic methods in python

前端 未结 3 930
[愿得一人]
[愿得一人] 2021-02-08 14:20

Is it possible to implement generic method handlers in python which allow for calling of non-existent functions? Something like this:

class FooBar:
  def __gener         


        
3条回答
  •  眼角桃花
    2021-02-08 14:42

    class FooBar:
        def __getattr__(self, name):
            def foo():
                print name
            return foo
    
    a = FooBar()
    a.helloThere()
    

提交回复
热议问题