[Tutor] The trap of the year

Corey Richardson kb1pkl at aim.com
Wed Jan 26 05:33:58 CET 2011


On 01/25/2011 06:49 PM, Steven D'Aprano wrote:
> Corey Richardson wrote:
> 
>> To be pedantic, a method _is_ a function, just under the umbrella of a
>> class, with it's parent object being passed to it.
> 
> To be even more pedantic, a method object is a wrapper (technically, a
> descriptor) around a function object. It's also slightly different
> between Python 2 and Python 3. Python 2 has bound and unbound method
> wrappers, depending on whether you call class.method or instance.method,
> but Python 3 gets rid of unbound methods and just returns the function
> object when you call class.method.
> 
> And of course, there are also "class methods" and "static methods", as
> well as custom-built method types.
> 
> Descriptors are fundamental to Python, but they're for advanced users.
> You can treat methods as just functions, except that they automatically
> get the first argument (usually called "self") automatically supplied.
> 
> 

Learning something every day, thank you Steven.

~Corey


More information about the Tutor mailing list