Duncan Booth wrote: > Chaz Ginger wrote: > >> Can someone explain what is really going on here? > > Think of 'from x import y' as an assignment. Roughly equivalent to: > > y = sys.modules['x'].y > > (except of course you don't have to have imported sys, and it will load the > module 'x' if it hasn't already been imported.) > >> b.py ---------------------- >> >> from a import foo > > In other words: > > foo = a.foo > > foo in module b is initialised from a.foo, but it is a separate variable. > So when a.foo is rebound that doesn't affect b.foo. > >> def b(): print foo >> >> c.py ---------------------- >> >> import a >> from b import b > > and here: > b = b.b > >> print 'per a.a() ',a.foo >> a.a(245) >> print 'expect 245 ', a.foo >> b() >> > >
Thanks, Duncan. It now makes sense. -- http://mail.python.org/mailman/listinfo/python-list