Global in multiple files
James Logajan
JamesL at Lugoj.Com
Sun Jun 10 14:14:27 EDT 2001
Artur Skura wrote:
> So, any ideas how I should cope with that and be able to use my
> global variable in different clases in different files?
Create a separate module, say globalVar.py, and put your globals into that
(it should set their initial values. E.g. myList = [ ]; myStuff = None).
Then use:
import globalVar
at the top of all your modules that need to access/update the globals. In
your code you then just reference as, say, globalVar.myList.append('some
value'), globalVar.myStuff = 3, etc. All your modules can now access and
update the global variables as needed and their global nature is also self
documented.
Hope this helps!
More information about the Python-list
mailing list