fork download
  1. class Foo:
  2. pass
  3.  
  4. def create_foo_method(method_name):
  5. def method_def(self):
  6. return method_name
  7. return method_def
  8.  
  9. for method_name in ["bar", "baz"]:
  10. setattr(Foo, method_name, create_foo_method(method_name))
  11.  
  12. foo = Foo()
  13. print(foo.bar())
  14. print(foo.baz())
Success #stdin #stdout 0.16s 10264KB
stdin
Standard input is empty
stdout
bar
baz