test2.py 643 B

123456789101112131415161718192021222324252627282930313233343536
  1. class Demo():
  2. def __init__(self):
  3. print("__init__")
  4. self.funcs = []
  5. self.funcs.append(self.a)
  6. self.funcs.append(self.b)
  7. self.funcs.append(self.c)
  8. self.val = 'ppp'
  9. def a(self):
  10. print('a')
  11. def b(self):
  12. print('b')
  13. def c(self):
  14. print(self.val)
  15. def get_funcs(self):
  16. return self.funcs
  17. class Test():
  18. def funcs_test(self):
  19. demo = Demo()
  20. funcs = demo.get_funcs()
  21. print('----------------------------')
  22. for func in funcs:
  23. demo.func = func
  24. demo.func()
  25. test = Test()
  26. test.funcs_test()