473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

global variables in module

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
Jul 18 '05 #1
2 3156
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
Jul 18 '05 #2
Harald Massa <cp*********@spamgourmet.com> writes:
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


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

and access the

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Larry L | last post by:
I have a Module that declares several arrays as public, some string, some integers. I then have 2 forms. Form A is the main form, that loads on start-up, and has a command button to open Form B. On...
8
by: David Hitillambeau | last post by:
Hi guys, As I am new to Python, i was wondering how to declare and use global variables. Suppose i have the following structure in the same module (same file): def foo: <instructions>...
2
by: Bryan Parkoff | last post by:
….I would like to know which is the best optimization to use global variable or global struct. I always tell C/C++ Compiler to turn on optimization. ….I use underscore between first name and...
17
by: MLH | last post by:
A97 Topic: If there is a way to preserve the values assigned to global variables when an untrapped runtime error occurs? I don't think there is, but I thought I'd ask. During development, I'm...
33
by: MLH | last post by:
I've read some posts indicating that having tons of GV's in an Access app is a bad idea. Personally, I love GVs and I use them (possibly abuse them) all the time for everything imaginable - have...
11
by: Capstar | last post by:
Hi, I am working on an application, which will run embedded without an OS. The app is build up out of a couple of well defined parts. At first I wanted to keep those parts seperated and use...
7
by: Michael | last post by:
Hi newsgroup, as the subject indicates I am looking for an advice using global variables. I am not if this problem is more about style then C. If its wrong in thi group, sorry. So I have a...
8
by: newbie | last post by:
Hello, I have questions about global variables in OOP (in general) and Python (in specific). I understand (I think) that global variables are generally not a good idea. However, if there are...
18
by: robert | last post by:
Using global variables in Python often raises chaos. Other languages use a clear prefix for globals. * you forget to declare a global * or you declare a global too much or in conflict * you...
0
by: Gary Herron | last post by:
Jacob Davis wrote: Yuck, YUCK, YUCK! You are breaking *so* many good-programming-practices, I hardly know where to start. First off: A python global is not what you think. There are *no*...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.