Module executed twice when imported!

Michael Abbott michael at
Fri Jun 30 21:32:41 CEST 2006

In article <05epg.2385$No6.49436 at>,
 John Salerno <johnjsal at> wrote:

> > (
> > "It is different from the import statement in that it does not use the
> > module administration --"
> Just after the above statement, it also says:
> "it reads the file unconditionally and does not create a new module."
> so perhaps that means that it isn't really being imported the second 
> time, just that the contents are being executed?

Interesting thought.

I'm not convinced, though: firstly, I read that statement as describing 
what happens to the file named in the execfile() statement;  and 
secondly, the problem *only* happens if the global dictionary passed to 
execfile() has a '__name__' and if the value of that key is sufficiently 
close to the name of the file being passed to execfile().

I found that passing __name__='whatever' resulted in normal import 
behaviour, and so does __name__='subtest', but curiously enough passing 
__name__='subtest.' results in the double import.

More information about the Python-list mailing list