How best to write this try/except block?

David Eppstein eppstein at ics.uci.edu
Wed Apr 3 17:14:23 EST 2002


In article <Xns91E5CE0E5919Dcliechtigmxnet at 62.2.16.82>,
 Chris Liechti <cliechti at gmx.net> wrote:

> if d.has_key(key):
>      foo = stuff(d[key])
> else:
>      foo = otherStuff(key)

I've seen a couple responses suggesting this.

Is there a reason why in modern Python versions one should still use 
has_key?  I like the syntax "if key in d" better.

-- 
David Eppstein       UC Irvine Dept. of Information & Computer Science
eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/



More information about the Python-list mailing list