methods 

Send to Kindle
home » snippets » python » methods



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