niklasro at gmail.com
Sun Sep 19 09:14:42 CEST 2010
On Sep 19, 2:31 am, alex23 <wuwe... at gmail.com> wrote:
> 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.
I try a file setting.py declaring it like this just loose in the file
not knowing much theory about it thinking it's easy and intuitive.
More information about the Python-list