global variable

Really a Python question, not a wxPython question, but...

I'd use a dictionary singleton (singleton recipe:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/102187).

Create a new global-data singleton class:

     # GlobalData.py
     class GlobalData( dict )
         __metaclass__ = Singleton

In your App class initialization or in your __main__,
get and initialize the singleton, so you know the
initial state:

     from GlobalData import GlobalData
     ...
     GlobalData()[ 'currentDate' ] = currentDate

Anywhere else you want to use and/or modify the shared
global data:

     from GlobalData import GlobalData
     ...
     # Get desired value
     desiredValue = GlobalData()[ desiredValueName ]
     # Change favorite color
     GlobalData()[ 'userFavoriteColor' ] = userFavoriteColor

etc.

- Sam

···

At 2004-06-29 10:54 AM +0530, you wrote:

i'm migrating an app from perl/tk to wxPython. In perl the app has a global
variable called currentdate. At the start it is initialised as the system
date. whenever the date is changed in the main window of the app, the
variable currentdate is changed also and is the default date in any screen
that uses date. my wxpython app consists of a series of files - one class per
file which deals with one windows. How do i implement the global variable in
this?
--
regards
kg

__________________________________________________________
Spinward Stars, LLC Samuel Reynolds
Software Consulting and Development 303-805-1446
http://SpinwardStars.com/ sam@SpinwardStars.com