set im_self

Michael Hudson mwh21 at cam.ac.uk
Wed Jun 23 13:28:34 EDT 1999


"Oleg Orlov" <orlov at diasoft.ru> writes:

> Hello.
> Is there any way to set im_self attribute (ie bind method object)?
> Thanks.

The `new' module can do this:

>>> class C:
...  def m(self):
...   print self
...
>>> c=C()
>>> c.m()
<__main__.C instance at 8111318>
>>> import new
>>> cm=new.instancemethod(C.m.im_func,c,C.m.im_class)
>>> cm()
<__main__.C instance at 8111318>

Be aware that RedHat up to version 5.2 (I think) shipped a Python
without the new module compiled in, so you'll need to recompile or
update from an Andrich rpm if you're lumbered with one of those.

HTH
Michael




More information about the Python-list mailing list