My scope is broke
Travis Beaty
t.beaty at mchsi.com
Fri Dec 20 23:12:59 EST 2002
Hello!
Once upon a time, Dennis Lee Bieber pressed the following keys in quick
succession ...
>The Apocalypse will NOT be televised... (will that do for the
>revelation?) <G>
>
Well, we're not missing much. Knowing my luck, it would be
pay-per-view, and the wife wouldn't let me press the right buttons ...
> The "global" keyword is used /inside/ a procedure to signify which
>variables exist outside of the procedure.
>
Ah ... yes, I had totally misunderstood what "global" does. I believe
I have a better grasp of global now. One quick question about a piece
of the code that you supplied, however:
> <snip>
>
>s = 0
>def Aglobal():
> global s
> s = 132 #this "s" is global from the view point of this
> #function
>
Had s not been defined in the outer scope, would the variable s declared
with global within Aglobal() still be accessible outside the function?
Or would s now be something like C++'s static int within Aglobal()?
I removed the "global" from my declarations in appvar, because they
would make no sense, as these declarations were in the outer scope of
the module.
><snip>
>
> -=-=-=-=-=-=-=-
>
> The OTHER problem I see is that you are using "from xyz import *" --
>this is seldom a recommended action; it makes all "names" in the top
>level of xyz become names in the top level of the module doing the
>import.
>
> "from appvars import *", makes all names local...
>
><mailstash>
>from appvars import * #makes user_preferences a local name of mailstash
> #in effect the name is mailstash.user_preferences
>
Okay, I changed the import line to "import appvars," and made the
changes in calling the variables that you suggested. Not surprisingly
... the fix worked, and I'm up and running. Thank you! But, I still
don't understand *why* the fix worked. I guess I'll still a little
unclear on this. The sole purpose of appvar is to declare variables and
constants which are global to the entire application. It does not
contain any functions or classes. By importing it with "from appvars
import *", I thought that I would basically be making a "syntactic
shortcut," as opposed to repeatedly typing the "appvar." qualifier. So
yes, it would be considered local in mailstash, but also local to
mailstash_gui.tmainform. But, would these be considered two different
variables in this case, in two different scopes?
>
><mailstash_gui.tmainform> #are you sure of the . -- you are defining a
> #package mailstash_gui containing a file tmainform?
>
Yes.
mailstash.py
appvars.py
/mailstash_gui
__init__.py
tmainform.py
I had intended the package mailstash_gui to contain all the modules that
contain classes pertaining to the application's GUI (pyGnome). Is this
standard procedure in Python applications?
Once again, thank you for your help, folks.
Travis Beaty
Mason City, Iowa.
More information about the Python-list
mailing list