Accessing and updating global variables among several modules

François Pinard pinard at iro.umontreal.ca
Thu Jul 17 16:05:25 EDT 2003


[Fuming Wang]

> The problem is caused by Python creating two copies of the module that is
> passed to the interpreter.

We were recently bitten by a variation on this problem.

A co-worker and I were writing one module each for a single project, both
modules were to derive classes from a common base class from the same module
`listes'.  Everything was to be installed in a single package `Lc'.

In his module, he wrote:

    from Lc import listes

while in my module I wrote:

    import listes

In fact, both `import' worked, yet `listes' was not the same object for each
of our viewpoints, and so, our classes did not have a common base.  Object
initialisation was modifying a supposedly common registry of created
objects, kept as a class variable in the base, so there was a problem.

P.S. - Or something similar, I'm not sure I remember correctly.  So many
things happen between a particular day and the next one! :-)

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard





More information about the Python-list mailing list