A better self
Louis M. Pecora
pecora at anvil.nrl.navy.mil
Sun Jul 21 09:56:18 EDT 2002
In article <mailman.1027189709.16845.python-list at python.org>,
<brueckd at tbye.com> wrote:
> Just an idea - since Python is so dynamic, instead of writing the
> function you write a string describing the function and have another
> function read it and generate a method that does all the 'self.' stuff.
> Obviously you'd have to think it through some, but this is definitely
> possible.
>
> In the above example, I assume MyCoolUnboundMethodMaker would read
> the string, and use it to generate a string like this:
>
> '''def NewMethod(self, arg):
> self.x = self.y * self.z + self.t * arg
> '''
>
> after which it would exec the string and then do a 'return NewMethod', and
> bingo, your class now has a method that performs that operation. It'd take
> some work to get it right the first time, but from then on you could reuse
> it for all your numeric work.
I gotta think about that one. Thanks.
--
Lou Pecora
- My views are my own.
More information about the Python-list
mailing list