[Tutor] class method: dynamic overload/++
Gregor Lingl
glingl at aon.at
Mon Dec 1 18:28:27 EST 2003
Tim Johnson schrieb:
>* Tim Johnson <tim at johnsons-web.com> [031201 13:25]:
>
>
>>Hi All:
>> Is it possible in python to replace (overload)
>>an existing class method with a new one of the same
>>name but with different functionality?
>>
>>
>
> Upon review, I could have made myself more clear.
>
> I should have asked:
> Is it possible to overload an existing method
> with another at runtime?
>
>
Hi Tim!
I'm not sure if it's this, what you want to know. I just played around
a little:
>>> class A:
def __init__(self):
self.u = 1
def p(self):
print self.u
>>> x = A()
>>> x.p()
1
>>> def q(self):
print 2*self.u
>>> A.p = q
>>> x.p()
2
>>>
Even if it doesn't help it's still funny
Gregor
> Hopefully that's clearer
> -----------------------
> I would welcome pointers to docs and keywords.
> - this is just R & D, not mission critical.
>
> TIA
> tim
>
>
>
More information about the Tutor
mailing list