[Python-Dev] functions vs methods (was Re: trunc())

Aahz aahz at pythoncraft.com
Sun Jan 27 21:53:09 CET 2008


On Sun, Jan 27, 2008, "Martin v. L?wis" wrote:
>
> Students just asked me why len() is not a method, and I didn't know a
> good answer; the same holds for many other builtins. This is a clear
> candidate for a method, IMO.

This is why len() is not a method:

    map(len, list_of_strings)

What I don't know is to what extent this argument still holds in the
presence of listcomps and genexps:

    [s.len() for s in list_of_strings]

However, you still need ``len`` as a function to pass around as a
callback in other cases where you need a generic function because the
type of your data is not predetermined.

In any event, I consider dropping len() from builtins to be gratuitous
breakage, even in 3.0.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"All problems in computer science can be solved by another level of     
indirection."  --Butler Lampson


More information about the Python-Dev mailing list