Guido's new method definition idea
Patrick Mullen
saluk64007 at gmail.com
Mon Dec 8 16:07:56 EST 2008
On Mon, Dec 8, 2008 at 12:55 PM, Arnaud Delobelle
<arnodel at googlemail.com> wrote:
> anthony.tolle at gmail.com writes:
>
>> class C:
>> def createfunc(self):
>> def self.func(arg):
>> return arg + 1
>>
>> Or, after the class definition is done, to extend it dynamically:
>>
>> def C.method(self, arg):
>> self.value = arg
>>
>> ...which would be the equivalent of the following:
>>
>> def method(self, arg):
>> self.value = arg
>> C.method = method
>
> What about the following then?
>
> functions = {}
>
> def functions['square'](x):
> return x*x
>
> def functions['cube'](x):
> return x**3
>
> --
> Arnaud
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Why not? "def ob.func" is fundamentally "def ob.__dict__["func"]" anyway.
I like this idea much better than the original proposal, even though
it is pretty much unrelated.
More information about the Python-list
mailing list