global variables in module

  • Thread starter Zunbeltz Izaola
  • Start date
Z

Zunbeltz Izaola

Hi to all!

I'm writing a GUI with wxPython. I want to save preferences and defaults
values in a configuration file. I'm going ot parse this file using
ConfigParse from the standar library.

In my application i've

MyApp(wxApp):
...
def OnInit(self):
..
cf = ConfigParse.ConfigParse()
cf.read(open("defaults.cfg"))

How can i use cf in other modules of the program. Did I need declare cf
global, or make it a module variable, ... Any hint, please

TIA

Zunbeltz
 
H

Harald Massa

Zunbeltz,
MyApp(wxApp):
How can i use cf in other modules of the program. Did I need declare cf
global, or make it a module variable, ... Any hint, please

is used the following approach:

1) defining one module named

ReportGlobals

loggedInUser="nasenbaer"
workerQueue=Queue.Queue()

there all varibles which are "konfiguration related" are defined, also
"programm global queues", "error loggers", "database connection pool"

All these variables are defined as module level variables
(on "indent 0" :))) )

2) in all modules of the programm I use

import ReportGlobals as gl

print "You are %s" % (gl.loggedInUser,)


HTH

Harald



and access the
 
Z

Zunbeltz Izaola

Harald Massa said:
Zunbeltz,


is used the following approach:

1) defining one module named

I've take another aproach. I've created a module where I define a class
derived from ConfigParse. I've take the idea from the source of idle.
ReportGlobals

loggedInUser="nasenbaer"
workerQueue=Queue.Queue()

there all varibles which are "konfiguration related" are defined, also
"programm global queues", "error loggers", "database connection pool"

All these variables are defined as module level variables
(on "indent 0" :))) )

2) in all modules of the programm I use

import ReportGlobals as gl

print "You are %s" % (gl.loggedInUser,)


HTH

Harald
Thanks for your answer

Regards,

Zunbeltz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top