packages, modules and double imports - oh my!
Dave Angel
davea at ieee.org
Mon Oct 3 14:54:26 EDT 2011
On 01/-10/-28163 02:59 PM, Chris Withers wrote:
> On 03/10/2011 11:22, Chris Rebert wrote:
>> http://docs.python.org/library/runpy.html :
>> "The runpy module['s] main use is to implement the -m command line
>> switch"
>> "If the supplied module name refers to a package rather than a normal
>> module, then that package is imported and the __main__ submodule
>> within that package is then executed and the resulting module globals
>> dictionary returned."
>
> Interesting, but doesn't help with the bizarre double-exec of
> module.py when it happens to be __main__...
>
> cheers,
>
> Chris
>
Sounds to me like you have a circular dependency. It's never a good
idea, and especially if you have a circular dependency on the script
itself, it'll get loaded twice. Once it comes in as __main__, and the
other time by its filename. So redesign the module to eliminate the
circulars. If a.py imports b.py, then b.py should not import a.py,
directly or indirectly.
You are lucky you got an explicit error; We've seen other people get
very obscure bugs when two instances of some module variables were in
existence.
DaveA
More information about the Python-list
mailing list