Why does Python mix OO concepts and non OO concepts for operation s on basic types?

A.Schmolck a.schmolck at gmx.net
Wed May 22 17:34:55 EDT 2002


Syver Enstad <syver-en+usenet at online.no> writes:

> jajvirta at cc.helsinki.fi (Jarno J Virtanen) writes:
> 
> > Wed, 22 May 2002 13:13:06 -0500 Michael Bauers wrote:
> > > 
> > > Why do you say x = []; x.append('a'), but get the length with len(a)
> > ?
> > 
> > > 
> > > Is there a reason for this sort of inconsistency?
> > 
> > why not check the FAQ?
> > 
> > 	http://www.python.org/cgi-bin/faqw.py?req=all#6.5
> 
> Yes, but the FAQ seems to be *very* old, it also says that in the
> distant future it may be possible to subclass built in types. 
> 
> I always have to back up in the editor when I am asking an object what
> length it has. Like this (I wanna know the length of object foo):
> foo. "Aw, It's not a method it's a function that calls a method with
> an unsightly name  behind the scenes" back the cursor up and write
> len(foo) instead of foo.len() which would be much more intuitive.

Well, it has its advantages:

seq = ["one-two-three", "i ii iii", (1,2,3)]
maxLen = max(map(len, seq))

alex



More information about the Python-list mailing list