import and shared global variables

Diez B. Roggisch deets at
Fri Mar 10 15:18:51 CET 2006

> I'm implementing a plugin-based program, structured like the example
> below (where m1 in the main module, loading m2 as a plugin).  I wanted
> to use a single global variable (m1.glob in the example) to store some
> config data that the plugins can access.  However, the output shown
> belown seems to imply that glob is *copied* or recreated during the
> import in m2.  Am I missing something? I thought m1 should be in
> sys.modules and not be recreated during the import in m2.

Yes, you are missing that your first glob is in __main__.glob, _not_ in

To make that happen, use something like this:

glob = [1]
def main():

if __name__ == "__main__":
    import m1


More information about the Python-list mailing list