Links
- Python Code Object Utilities
- Doesn't wrap the function – but replaces the code object.
- Makes it is possible to either execute additional code before/after the original code or to replace the original code completely.
- Add bound methods to instantiated objects in Python
- Quick One-Positional-Argument Function Currying In Python
Snippets
# Make a bound method from an unbound method and then # stick it on an object (e.g. when you get the object # swig wrapped from somewhere else.) class Foo(swig_foo): def __enter__(self): return self def __exit__(self, exc_type, exc_val, exc_tb): self.RELEASE_RESOURCE() def NewFoo(): foo = swig_new_foo() foo.__enter__ = Foo.__enter__.__get__(foo, Foo) foo.__exit__ = Foo.__exit__.__get__(foo, Foo) return foo