Learning inheritance

Niklasro niklasro at gmail.com
Sat Sep 18 19:19:56 EDT 2010


On Sep 18, 4:13 pm, "bruno.desthuilli... at gmail.com"
<bruno.desthuilli... at gmail.com> wrote:
> On 18 sep, 17:25, Niklasro <nikla... at gmail.com> wrote:
>
> > Hi
> > How can I make the visibility of a variable across many methods or
> > files? To avoid repeating the same line eg     url =
> > os.environ['HTTP_HOST'] if os.environ.get('HTTP_HOST') else
> > os.environ['SERVER_NAME']
>
> First learn to use Python correctly:
>
> url = os.environ.get("HTTP_HOST", os.environ["SERVER_NAME"])
>
> => dict.get(key, default=None)
>
> Also and FWIW, neither HTTP_HOST not SERVER_NAME are really urls...
>
> > I repeat for many methods. So declaring it
> > to a super class and inheriting it is my plan. Do you agree or propose
> > otherwise?
>
> Not enough background to answer.

Thanks for replying and informing correctness. More background is the
variable I want accessible for many functions and files either is
HTTP_HOST or SERVER_NAME used as beginning of url or resource locator
indicated where the software is used. Instead of declaring the
variable many times feasibility study is how to minify number of times
I declare the same variable. I got 2 files main.py and i18n both with
webapp request handlers which I would like access the variable.
Thanks
Niklas R



More information about the Python-list mailing list