[wxPython-users] Accessing Variable Across Modules

Rich Shepard rshepard at appl-ecosys.com
Fri Nov 3 12:24:07 PST 2006


On Fri, 3 Nov 2006, Dan Cherry wrote:

> You could pass 'projname' to b.py as a parameter when you instantiate the
> class (assuming that can happen after the UI has determined what the
> projname will be), and assign that value in your b.py class _init_ to
> something like 'self.projname'.  This would make it available to
> everything within that instance of b.py during subsequent calls.
>
> In my opinion, the more variables you pass by parameter and access by
> functional returns, the more reliable your modules and functions will be,
> and the less you will have to keep straight in your head while
> programming.  Others may disagree.

   Thank you, Dan. That's an excellent suggestion.

   Interestingly enough, I stumbled into the middle of a thread on the python
mail list that addressed this exact issue. I created a new module,
config.py, that contains only "projname = ' '." By importing config in all
files needing that variable, it's made available to them.

   This is, apparently, the same approach used by the 'singleton pattern' but
I've no idea what that is or when it's appropriate.

   Now to fix the next bad reference across modules ...

Rich

-- 
Richard B. Shepard, Ph.D.               |    The Environmental Permitting
Applied Ecosystem Services, Inc.(TM)    |            Accelerator
<http://www.appl-ecosys.com>     Voice: 503-667-4517      Fax: 503-667-8863




More information about the wxpython-users mailing list