Guido's new method definition idea

Carl Banks pavlovevidence at gmail.com
Sat Dec 6 16:15:19 EST 2008


On Dec 6, 12:47 am, "Patrick Mullen" <saluk64... at gmail.com> wrote:
> Could I do something like this:
>
> def a.add(b): return a+b
>
> Outside of a class?  Of course then that makes you think you could do
> 5.add(6) or something craaaazy like that.  (I mean, you can do
> (5).__add__(6) but that's something else entirely)


I'd be inclined to think that this defines an instancemethod on an
existing object a.  In other word, I'd read the following two lines as
more or less equivalent.

def a.add(b): return a+b

a.add = lambda b: a+b


Just as the following are equivalent:

def foo(): return bar

foo = lambda: bar


I had been -0 on this, but now I think I'm -1.


Carl Banks



More information about the Python-list mailing list