Difference between 'function' and 'method'

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Mar 5 04:01:32 CET 2008


En Wed, 05 Mar 2008 00:30:26 -0200, <castironpi at gmail.com> escribió:
> On Mar 4, 8:11 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:
>> En Tue, 04 Mar 2008 16:45:40 -0200, <castiro... at gmail.com> escribió:
>>
>> >> Can you overload -type-'s decision of what to 'bind'?... whenever it
>> >> is it makes it.
>>
>> >>>> from types import FunctionType, MethodType
>> >>>> class A( FunctionType ): pass
>> > ...
>> > Traceback (most recent call last):
>> >   File "<stdin>", line 1, in <module>
>> > TypeError: type 'function' is not an acceptable base type
>>
>> Use delegation instead of inheritance. This class is almost  
>> indistinguishable from a true function (when used as a method):

[... long interactive example ...]

> I actually don't believe you-- bar is not bound to an instance when P
> is initialized... er, instantiated.  However, the evidence indicates
> my belief mechanism is faulty... and rather conclusively at that.
> <moves to acquire new evidence>  If P calls __get__( you ), is p a
> gotcha?

I didn't cheat, that was an actual Python interactive session. So you'll  
have to formulate a new theory taking into account the new facts... or  
read how the descriptor protocol works http://www.python.org/doc/newstyle/
I don't understand your last sentence.

-- 
Gabriel Genellina




More information about the Python-list mailing list