Module loading trickery

Dave Angel davea at ieee.org
Tue Oct 5 22:36:58 EDT 2010



On 2:59 PM, Thomas Jollans wrote:
> <snip>
> % cat a.py
> foo = 'Meh.'
> import b
>
> % cat b.py
> from a import foo
>
> print(foo)
>
> % python a.py
> Meh.
> %
>
>

But there are now two modules containing separate items foo, one is 
called __main__, and the other is called a.

The former is the script you ran, and the latter is the module imported 
by b.  Several problems could occur, including if foo were a list, and b 
appended to it, the original script wouldn't see the change.

DaveA




More information about the Python-list mailing list