Re: Adding functions to classes after definition

2007-01-08 Thread Vasily Sulatskov
A nice guide to descriptors http://users.rcn.com/python/download/Descriptor.htm -- http://mail.python.org/mailman/listinfo/python-list

Re: Adding functions to classes after definition

2007-01-08 Thread Gabriel Genellina
At Monday 8/1/2007 21:47, Gerard Brunick wrote: Consider: A) >>> class C(object): ... pass ... >>> def f(*args): ... print args ... >>> C.f = f >>> C.f >>> c=C() >>> c.f() (<__main__.C object at 0x04A51170>,) And B) >>> del c >>> C.f = types.MethodType(f, None, C) >>> C.f

Adding functions to classes after definition

2007-01-08 Thread Gerard Brunick
Consider: A) >>> class C(object): ... pass ... >>> def f(*args): ... print args ... >>> C.f = f >>> C.f >>> c=C() >>> c.f() (<__main__.C object at 0x04A51170>,) And B) >>> del c >>> C.f = types.MethodType(f, None, C) >>> C.f >>> c = C() >>> c.f() (<__main__.C object at 0