global declarations
Lee Harr
missive at frontiernet.net
Mon Dec 23 18:36:59 EST 2002
In article <mailman.1040605949.27825.python-list at python.org>, Frederik Fuest:
> Hi,
>
> i've a problem with the 'global variables' in classes.
> It seems, that it isnt possible to make a real global declaration of
> lists or strings in a class. Whatever i try, if i call functions from
> other functions in my class, these functions are no longer able to know
> the global variables!?
>
> How could i handle this?
>
I do not know if this helps, but...
What I did is create a separate module where I store these "global"
values. Then the other modules import it, and read or write in there.
For instance:
# conf.py
WINWIDTH = 800
WINHEIGHT = 600
# Screen.py
import conf
window = Window(conf.WINWIDTH, conf.WINHEIGHT)
# myProgram.py
import conf
conf.WINWIDTH = 1024
conf.WINHEIGHT = 768
import Screen
Someone will probably come along and tell me why this is horribly
broken. I am happy to hear any suggestions.
More information about the Python-list
mailing list