Scope and program structure problems

John Dann news at prodata.co.uk
Tue Jul 1 09:43:52 EDT 2008


Many thanks for the repsonse - much appreciated. 

And sorry - yes I was probably compounding two separate issues here -
the GUI one and the variable scope one. Maybe the wxPython list would
be the best place to ask more about the GUI side of things.

Then actually I can simplify my remaining question quite a lot - I
know you've partly answered this already but let me just rephrase
this:

It must be commonplace to first use a variable or object within one
function in a module and then want to use it again  - perhaps still
with the same value as in the first function - in a second function.

So what's the recommended Python way round this? If I was using .Net
then I'd be declaring the variables/objects explicitly and could set
their scope according to how/where they were declared. But if the
Python way is not to declare vars before use then this must create
some problems for cross-function use.

So it is best to declare such vars at the module level (ie outside of
a function) and set eg to Null/None or to assign them with a keyword
such as global or static (assuming that concept applies in Python) at
first use inside a function or what?

JGD



More information about the Python-list mailing list