getting as global as __builtin__

Mitja tezt at email.si
Mon Apr 12 16:27:03 EDT 2004


How to make a variable visible from __main__ as well as all other imported
modules? I.e., how to make it share the scope with __builtin__? Saying
__builtin__.foo='bar' works, but seems messy - foo is far from a built-in
thingy.

Background:
---------------------
I'm writing a web application with a central module and a few peripheral
ones, which provide the content of the web page to the main module. The only
script ever called is main.py, which then makes use of others via import.

All of these modules have to have access to some variables (e.g. HTTP GET
parameters), which are all gathered in a module common.py. Therefore, all
modules "import common".

Thing is, some of these variables are a result of database queries, so the
can take some time to get. I would like to have them computed only once (at
a specific function call) and then keep them somewhere where they are
visible to all the modules throughout the execution of the program. This
way, we come to the problem from the first paragraph
-------------------

Are there better ways of doing it than __builtin__? Or is the entire
approach wrong? Thanks for answers/suggestions,

Mitja





More information about the Python-list mailing list