How best to write this try/except block?

Remco Gerlich scarblac at pino.selwerd.nl
Thu Apr 4 02:09:43 EST 2002


David Eppstein <eppstein at ics.uci.edu> wrote in comp.lang.python:
> 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.
 
Are you sure you have the newest Python everywhere you want to use it? I'm
not. Why make your programs incompatible with such a trivial change?

-- 
Remco Gerlich



More information about the Python-list mailing list