Strange compiler warning

Steve Holden sholden at
Tue Oct 8 14:06:38 CEST 2002

"Robin Becker" <robin at> wrote in message
news:KdQzQgAUSpo9Ewch at
> In article <3da227db$1 at>, Peter Hansen
> <peter at> writes
> >Robin Becker wrote:
> .......
> >Basically:
> >
> >1. the "global" statement applies for the following scope of the
> >function, so you need only one,
> >
> >2. you can check if it exists simply by trying to reference it,
> >
> >3. using exceptions is generally better than not.
> >
> >But what are you really trying to accomplish?
> >
> >-Peter
> >
> that will do. I keep thinking that global brings something into scope,
> but in fact it's only declarative and doesn't have to exist already.
> As for the try except is it really true that
> try:
>     _dbg
> except:
>     _dbg = .....
> is better than
> if not globals().has_key('_dbg'):
>     _dbg = .....
Who's to say which is better? They are certainly *different*, since the
former will pick up _dbg from any of the usual suspects' scope, whereas the
latter explicitly tests just one single namespace.

When _dbg is declared global (sorry, I was picking nits) then it's perhaps a
matter of taste (<gasp>, you mean there really *is* more than one way to do
it?). Who's to say which is faster? Only a timing test will tell you. Was
speed your criterion for "better"? Even if it's readability, ut's still
pretty much a matter of taste.

Steve Holden                        
Python Web Programming       
Previous .sig file retired to          

More information about the Python-list mailing list