grahn+nntp at snipabacken.se
Sun Sep 19 01:15:05 CEST 2010
On Sat, 2010-09-18, Niklasro wrote:
> 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'] I repeat for many methods. So declaring it
> to a super class and inheriting it is my plan. Do you agree or propose
Inheritance is not the main tool for sharing code. Just make it a
function and place it in one of your modules (files):
"""Return the environment's $HTTP_HOST if
it exists, otherwise $SERVER_NAME or (if that
doesn't exist either) None.
Perhaps you are focusing too much on inheritance in general.
I personally almost never use it in Python -- it has much fewer
uses here than in staticaly typed languages.
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
More information about the Python-list