Learning inheritance
alex23
wuwei23 at gmail.com
Sat Sep 18 22:31:39 EDT 2010
Niklasro <nikla... at gmail.com> wrote:
> I got 2 files main.py and i18n both with
> webapp request handlers which I would like access the variable.
I'd probably use a module for this. Create a third file, called
something like shared.py, containing the line that bruno gave above:
url = os.environ.get("HTTP_HOST", os.environ["SERVER_NAME"])
Then from within both main & i18n you can 'import shared' and access
the variable as 'shared.url'.
Python only actually executes a module the first time it's imported,
every other import will be given a reference to the same module
object. This also lets you share temporary data between modules. Any
module that imports 'shared' can add an attribute to it ('shared.foo =
"barbaz"') that will be visible to all other modules that have (or
will have) imported it.
More information about the Python-list
mailing list