Python 2.6 Global Variables
benjamin.kaplan at case.edu
Fri Oct 30 00:50:41 CET 2009
On Thu, Oct 29, 2009 at 7:11 PM, AK Eric <warpcat at sbcglobal.net> wrote:
>> Good that you're not advocating it, because IMHO it's bad practice to
>> have circular import dependencies. By using the __main__ alias, you
>> avoid the worst problems, but that just means the others are more subtle.
> I figured I'd get that kind of response, not that it's incorrect ;)
> Great power\great responsibility\etc.
> As I understand it, when you enter Python statements at the
> interactive prompt, it's adding the result directly to ___main___
> (which for lack of a better term I like to call 'universal' scope...
> rolls off the tongue better than 'doubleunderscore main
>>>> foo = 23
>>>> import __main__
>>>> print __main__.foo
> While this might not be the most common way of working for most people
> (I'm guessing most folks are in a nice cozy IDE), people working this
> way are mucking about in the 'universal' scope without (possibly) even
> knowing it.
Or, you could use any other random module for this like, say, a module
made specifically for this purpose and given a name like "config.py"
or "settings.py" or something like that which describes what you're
using it for. You don't have a "universal" scope- it's the
module-level scope of the script that is actually run (or the
interactive interpreter in this case).
More information about the Python-list