On Sep 18, 4:15 pm, Jorgen Grahn <grahn+n...@snipabacken.se> wrote: > On Sat, 2010-09-18, Niklasro 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'] I repeat for many methods. So declaring it > > to a super class and inheriting it is my plan. Do you agree or propose > > otherwise? > > Inheritance is not the main tool for sharing code.
That statement might be a little too general to be true. Inheritance is a (or the) main tool for different objects to share behavior, which is implemented by code. So when your program is organized around objects, it is the (or a) main tool. You are right that you shouldn't rework your code into an OO style simply because you want to share code. I think that's what you meant. > Just make it a > function and place it in one of your modules (files): Or even just make it a global variable in the module (which would work in this case, unless you plan to update the environment within the program). Carl Banks -- http://mail.python.org/mailman/listinfo/python-list