How best to write this try/except block?
Erno Kuusela
erno-news at erno.iki.fi
Thu Apr 4 07:58:02 EST 2002
In article <a8fba8$ln8$1 at panix2.panix.com>, roy at panix.com (Roy Smith)
writes:
| I've got a dictionary d, which may or may not have a value I'm looking
| for. If it does, I want to do a few things. If it doesn't, I want to
| do a few other things.
this isn't suitable if you can have None values, but when
you don't, it can let you get away with writing key only once.
value = d.get(key)
if value is None:
otherStuff()
else:
stuff()
-- erno
More information about the Python-list
mailing list