Difference between 'function' and 'method'
gagsl-py2 at yahoo.com.ar
Fri Mar 7 02:10:31 CET 2008
En Thu, 06 Mar 2008 22:56:33 -0200, <castironpi at gmail.com> escribió:
> On Mar 6, 5:35 am, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:
>> p = P()
>> print p.bar.func_name # -> bar
>> p.bar.im_func.anotherattribute = 1
>> print p.bar.anotherattribute # -> 1
>> (the attribute must be set on the *function* itself if you want it to
>> somewhat persistent; methods are usually volatile objects)
> You read my mind.
You could try to write in a way that reading your mind isn't necesary...
> I was just getting:
> assert p.bar is p.bar
> and failing.
> But if you set them on im_func, instances don't have their own.
Instances don't have their own methods either. What do you actually want
to do? If you need a method with per-instance attributes, that looks like
another object to me.
More information about the Python-list