Variable scope question.. singletons?

Gordon McMillan gmcm at hypernet.com
Sun Nov 14 22:24:12 EST 1999


Adam Vandenberg asks:

> I have a bunch of modules that will be used by a bunch of top-level scripts
> (cgis).
> Each top-level script is going to: "import prefs" which I want to check
> cookies
> and fill out a Prefs class.
> So far OK.
> 
> Now, is there any way to make this class "more global" so that any of the
> modules I import can access it?
> I guess this is sort of like declaring the variable "extern".
> 
> Any thoughts? 

Sometimes. Rarely on Sundays.

> Does this make sense?

Not an iota of a scintilla <wink>.

The very first import will install the module in sys.modules. 
Subsequent imports will simply return references to the thing 
in sys.modules. So, in the absense of bizarre import hooks, it 
already is "extern".

returning-to-Sunday-night-oblivion-ly y'rs

- Gordon




More information about the Python-list mailing list