Python: Do something for any method of a class?

前端 未结 3 1194
自闭症患者
自闭症患者 2021-02-19 03:01

Say I have a class with a bunch of methods:

class Human():

  def eat():
    print(\"eating\")

  def sleep():
    print(\"sleeping\")

  def throne():
    print         


        
3条回答
  •  醉梦人生
    2021-02-19 03:21

    If you want to have arguments as well, you can try using metaprogramming to alter the class methods themselves to run a pre/post operation, like the answer to How to run a method before/after all class function calls with arguments passed?

提交回复
热议问题