Complaint Dept: My shoes!

.:|:. ng at hardlight.couk.com
Fri Apr 14 05:50:58 EDT 2000


<musingattheruins at my-deja.com> wrote in message
news:8d4s4d$mvr$1 at nnrp1.deja.com...
> 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
>    else:
>       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.


try

if shoe:
    print shoe, hit_on_head()

an exception is appropriate

Matt





More information about the Python-list mailing list