Strange compiler warning

Peter Hansen peter at engcorp.com
Thu Oct 10 00:37:09 CEST 2002


Robin Becker wrote:
> In article <3da227db$1 at news.sentex.net>, Peter Hansen
> <peter at engcorp.com> writes
>>3. using exceptions is generally better than not.
>>
>>But what are you really trying to accomplish?

> As for the try except is it really true that
> 
> try:
>     _dbg
> except:
>     _dbg = .....
> 
> is better than
> 
> if not globals().has_key('_dbg'):
>     _dbg = .....
> 

[Insert Steve's response here, but also:]

It's not necessarily better.  That's why I said both "generally",
above, and "what are you really trying to accomplish?"

Once we know exactly what you intended, it may become
feasible to discuss which really _is_ better.  Until
then, I can say only that "except NameError" (and note
it should NOT be just "except") is more readable _to me_
than the lengthy expression you used.  Just personal taste,
at this point.  Oh, also probably faster, since it is
not executing two or more Python function calls to do
the job, if that matters to you.

-Peter




More information about the Python-list mailing list