[Tutor] Re: global

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Mon Nov 17 21:43:43 EST 2003



On Mon, 17 Nov 2003, RoT wrote:

> Let us sit on the grass and tell stories of RoT
>
> > This problem tends to crop fairly regularly in my programming:
> >
> > global dummy
> > global doit
> >
> > class dostuff:
> >       def=A0__init__(self):
> >                try:
> >                        do=A0some=A0stuff
> >                        if=A0doit=A0=3D=3D=A0True=A0and=A0dummy=A0=3D=3D=
=A0False:
> >                                do=A0some=A0more=A0stuff
> >
> >                        except=A0AttributeError:
> >                                print=A0"I=A0said=A0dont=A0do=A0it=A0if=
=A0it=A0is=A0Tuesday"
> >                                #=A0Global=A0dummy=A0(this=A0works=A0but=
=A0gives=A0a=A0warning=A0all=A0the=A0time)
> >                                dummy=A0=3D=A0True
> >       def=A0morestuff(self):
> >               do=A0morestuffx
> >
> >x =3D raw_input("shall I do this thing, dont do it if it is Tuesday")


Hi RoT,


I have a slightly silly question: are you really using global variables in
your regular programs, or are you just trying to learn how to use
'global'?


If it's the former, then we have to recommend: don't use globals if you
can help it.  They're not automatically evil, but they seem to be all too
easy to abuse.


But I have to admit: I have no clue about what the example above is trying
to accomplish.  *grin* Can you show us another concrete example where you
use globals?  If you're regularly using global variables, we need to see
some examples and find out why they're necessary in the code.


Talk to you later!




More information about the Tutor mailing list