On Fri, 30 Jun 2006 19:13:00 +0100, Michael Abbott <[EMAIL PROTECTED]> wrote:
>Bump
>
>In article <[EMAIL PROTECTED]>,
> Michael Abbott <[EMAIL PROTECTED]> wrote:
>
>> --- test.py ---
>> import imptest
>> execfile('subtest.py', dict(__name__ = 'subtest.py'))
>> --- imptest.py ---
>> print 'Imptest imported'
>> --- subtest.py ---
>> import imptest
>> ---
>>
>>    $ python test.py
>>    Imptest imported
>>    Imptest imported
>>    $
>
>I claim this as an unreported (and highly obscure) Python bug.

You set __name__ to 'subtest.py' when executing subtest.py which made
the import system believe that when it found imptest.py it was being
imported as a *sibling* of the running module, which was subtest.py,
making the module being imported subtest.imptest.  Since the first
imptest was imported by the name imptest, subtest.imptest was determined
to be a different module and re-executed.

Set __name__ to 'subtest' as it would be if you had really imported
subtest and the import system will correctly name the modules, causing
imptest to be imported only once.

Jean-Paul
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to