List - rotate

Joachim Kaeber joachim.kaeber at imk.fraunhofer.de
Fri Jan 25 10:15:36 EST 2002


Hi all,

ameoba wrote:

> If it can't be done with a built-in class like string, can methods be added
> to user-defined classes outside of the original class definition without
> subclassing them?
> 
> Not so much that I want to do this, just that I'm curious as to how dynamic
> of an environment Python really is.

Yes, it is very, very runny -- erm, dynamic...

Python 2.2 (#9, Jan  4 2002, 13:11:39)
[GCC 2.96 20000731 (Mandrake Linux 8.1 2.96-0.62mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class A: pass
...
>>> a=A()
>>> def f(self): print self
...
>>> A.f=f
>>> a.f
<bound method A.f of <__main__.A instance at 0x81e6f8c>>
>>> a.f()
<__main__.A instance at 0x81e6f8c>

Best regards,

Joachim Kaeber



More information about the Python-list mailing list