Complaint Dept: My shoes!

musingattheruins at musingattheruins at
Thu Apr 13 18:20:47 CEST 2000

If shoe is None then len(shoe) raises an exception.  Would be nice if
len(None) was 0 and NOT raise an exeption.

Example: (Python 1.5.2)

def show_shoe_wear_to_complaint_dept(name):
   if name == "Idle":
      return None
      return "pick up hammer..."

def hit_on_head(): return "POW!!!"

shoe = ""
shoe = show_shoe_wear_to_complaint_dept("Idle")
if len(shoe)>0: print shoe, hit_on_head()

If len(shoe) returned 0 then the example would work without error, the
example above raises an exception whenever Idle shows his shoe to the
complaint department.

The work around for the above is....
shoe = show_shoe_wear_to_complaint_dept("Idle") or ""
which gets rid of the problem but feels weird.

On the other hand, if len(shoe) returned None then we would have to
discuss why the following prints "oww!"

if None>1: print "oww!"

and maybe we don't want to go there.

L8R :-)

Sent via
Before you buy.

More information about the Python-list mailing list