Re: [Tutor] Dynamically changing a class

2007-09-06 Thread Eike Welk
On Wednesday 05 September 2007 16:59, Jason Doege wrote: > Thanks for the good and useful information on this. Now for the > why... > > I am building an API and for various reasons I have chosen Python > to implement it. I'd like to separate the implementation from the > interface as, for instance,

Re: [Tutor] Dynamically changing a class

2007-09-05 Thread Kent Johnson
Kent Johnson wrote: > Jason Doege wrote: >> I am building an API and for various reasons I have chosen Python to >> implement it. I'd like to separate the implementation from the interface >> as, for instance, C++ does with separate .hpp and .cpp files. Apart from >> defining a class with a bunch o

Re: [Tutor] Dynamically changing a class

2007-09-05 Thread Ricardo Aráoz
Kent Johnson wrote: > Ricardo Aráoz wrote: > >> Yep. And once you've got it pls explain it too me, too lazy today to >> pick the manual. :) > > I included a link to my explanation previously. I'm too lazy to try to > do better. > LOL, too tired yesterday to even think straight. Thanks for your

Re: [Tutor] Dynamically changing a class

2007-09-05 Thread Kent Johnson
Jason Doege wrote: > Thanks for the good and useful information on this. Now for the why... > > I am building an API and for various reasons I have chosen Python to > implement it. I'd like to separate the implementation from the interface > as, for instance, C++ does with separate .hpp and .cpp f

Re: [Tutor] Dynamically changing a class

2007-09-05 Thread Jason Doege
Thanks for the good and useful information on this. Now for the why... I am building an API and for various reasons I have chosen Python to implement it. I'd like to separate the implementation from the interface as, for instance, C++ does with separate .hpp and .cpp files. Apart from defining a c

Re: [Tutor] Dynamically changing a class

2007-09-05 Thread Kent Johnson
Ricardo Aráoz wrote: > Yep. And once you've got it pls explain it too me, too lazy today to > pick the manual. :) I included a link to my explanation previously. I'm too lazy to try to do better. > Any easier way? Easier how? I don't know what could be easier to implement than a single functi

Re: [Tutor] Dynamically changing a class

2007-09-05 Thread Ricardo Aráoz
Alan Gauld wrote: > "Kent Johnson" <[EMAIL PROTECTED]> wrote > >>> Wanted to change the mfunc method but ONLY for an instance, not a >>> class: >> I believe the correct way to do this is to use the __get__() method >> of >> the function object to create a bound method and assign that to the >> i

Re: [Tutor] Dynamically changing a class

2007-09-05 Thread Alan Gauld
"Kent Johnson" <[EMAIL PROTECTED]> wrote >> Wanted to change the mfunc method but ONLY for an instance, not a >> class: > > I believe the correct way to do this is to use the __get__() method > of > the function object to create a bound method and assign that to the > instance attribute: Wow!

Re: [Tutor] Dynamically changing a class

2007-09-04 Thread Kent Johnson
Ricardo Aráoz wrote: > So lets take it a notch up. > Wanted to change the mfunc method but ONLY for an instance, not a class: > MyObj = MyClass() MyObj.mfunc(data) > pre change behavior MyObj.mfunc = newfunc MyObj.mfunc(data) > Traceback (most recent call last): > File "", li

Re: [Tutor] Dynamically changing a class

2007-09-04 Thread Ricardo Aráoz
Alan Gauld wrote: > "Jason Doege" <[EMAIL PROTECTED]> wrote > >> I'd like to change the behavior of a class' member function >> dynamically >> such that, once changed, all objects of the type would see the new >> behavior. > > class MyClass (object) : >> def mfunc(self, data): >>

Re: [Tutor] Dynamically changing a class

2007-09-04 Thread Alan Gauld
"Jason Doege" <[EMAIL PROTECTED]> wrote > I'd like to change the behavior of a class' member function > dynamically > such that, once changed, all objects of the type would see the new > behavior. class MyClass (object) : > def mfunc(self, data): >print 'pre change behavior' >

[Tutor] Dynamically changing a class

2007-09-03 Thread Jason Doege
Hi All, I'd like to change the behavior of a class' member function dynamically such that, once changed, all objects of the type would see the new behavior. For instance: >>> class MyClass (object) : def mfunc(self, data): print 'pre change behavior' >>> aMyClassObj = MyClass() >>