[issue12554] Failed imports clean up module, but not sub modules

R. David Murray report at bugs.python.org
Thu Jul 14 03:28:58 CEST 2011


R. David Murray <rdmurray at bitdance.com> added the comment:

In fact, to hopefully make perfectly clear what is going on here, let me demonstrate that *any* executable statement in the module that fails to load is executed if it occurs before the error that causes the load failure:

    rdmurray at hey:~/python/p32>cat temp.py
    import os

    print('foo:', hasattr(os, 'foo'))

    try:
        import temp2
    except AttributeError:
        print('attribute error')

    print('temp2:', 'temp2' in globals())
    print('foo:', hasattr(os, 'foo'))
    rdmurray at hey:~/python/p32>cat temp2.py
    import os

    os.foo = 2
    os.bar

    rdmurray at hey:~/python/p32>./python temp.py
    foo: False
    attribute error
    temp2: False
    foo: True

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12554>
_______________________________________


More information about the Python-bugs-list mailing list