Global variable visibility

David LeBlanc whisper at oz.net
Thu Oct 31 18:41:56 EST 2002


I have main.py which imports database.py, commands.py

Global variable Db is initialized in main.py after importing database.py but
before importing commands.py. Commands.py uses Db, but can't "see" it in
main.py. Is there a way to make it so that commands.py picks up Db, or do I
have to do as I did and create a Db = none at the commands.py global level
and then pass in an initializer for the global? This variable is used so
pervasivly that it doesn't make sense to pass it as an argument to every
function.

Is there a fully qualified name for a global in main that could be used from
an import?

A pointer to a general discussion of this issue would be appreciated too. I
can think of other related questions to ask, for example: If I create Db in
database.py, I can refer to it as database.Db in main - can I do the same
thing in commands.py - refer to it as database.db, or would I have to import
database.py into commands.py too?

David LeBlanc
Seattle, WA USA





More information about the Python-list mailing list