On Fri, Mar 30, 2007 at 01:43:41PM +0200, Aidas Bendoraitis wrote: > > Let's say I have the files main.py, a.py and b.py > > main.py: > ----------- > x="some local value" > import a > ... > > > a.py: > ----------- > x="some other local value" > import b > ... > > > b.py: > ----------- > def test(): > print x > > ---------------------- > Is it possible to access the x of the module a.py in the module b.py? > What would be the functions/statements to make it possible? Or in > general, how to access the locals of the importing ( not imported!!!) > module?
Well, you have a circular import here that may cause you problems. Neither module could finish loading because it depends on the other being imported which depends on the other being imported which depends on the other being imported .... But, this could work: a.py: -------------------------------------------------------------------------------- x = 'some local value' -------------------------------------------------------------------------------- b.py: -------------------------------------------------------------------------------- x = 'some other local value' def print_a_x(): import a print a.x # prints 'some local value' def print_x(): print x # prints 'some other local value' -------------------------------------------------------------------------------- Hope this helps. -Forest
signature.asc
Description: Digital signature