Complaint Dept: My shoes!

Jeff Bauer jbauer at rubic.com
Fri Apr 14 10:24:52 EDT 2000


aflinsch wrote:
> musingattheruins at my-deja.com wrote:
> >
> > If shoe is None then len(shoe) raises an exception.
> > Would be nice if len(None) was 0 and NOT raise an 
> > exeption.
> >
> I think I would prefer it if len(None) returned None. 
> Makes a bit more sense to me having an unsized object 
> return None, rather than zero.

It's no more appropriate for len() to return
a value for None than for it to return a
value for the length of an integer, a function,
or an open socket connection.   In all cases
the appropriate action is to raise a TypeError.

This isn't an argument in favor of purity of
design (or whatever).  It's of practical consequence 
for the interpreter to pass useful information back
to the user (in the form of an exception), rather 
than for the interpreter to assume it understands 
the programmer's intentions.

Jeff Bauer
Rubicon Research




More information about the Python-list mailing list