Re: Python-specific question: variable scope

2007-03-30 Thread Aidas Bendoraitis
It's not strongly related to some specific problem, but more to the better python perception and self-training. Thank you all for your time and attention. Thank you, Jerremy D, for the interesting solutions. Regards, Aidas Bendoraitis [aka Archatas] On 3/31/07, Forest Bond <[EMAIL PROTECTED]>

Re: Python-specific question: variable scope

2007-03-30 Thread Forest Bond
On Fri, Mar 30, 2007 at 08:07:51PM +0200, Aidas Bendoraitis wrote: > > Actually the was no circular import since I haven't imported a from b, > but just b from a. Sorry, mis-read your code, I thought there were only two modules. > And unfortunately your answer didn't solve the original question,

Re: Python-specific question: variable scope

2007-03-30 Thread Jeremy Dillworth
Here's a few ideas: Solution 1 - use the __main__ module The downside to this is that it always reads x from the "top-level" module, in other words, the script that is being run. So when you run a1, you'll get "a1" when you run a2 module b will then find "a2". a1.py -- import

Re: Python-specific question: variable scope

2007-03-30 Thread Jeremy Dunck
On 3/30/07, Jeremy Dunck <[EMAIL PROTECTED]> wrote: ... > In general, no. Python is lexically scoped, so that when b.test is > called, it checks the scope of test, then b, then __builtins__, then > fails with NameError. Good intro to scoping, if needed: http://en.wikipedia.org/wiki/Dynamic_scopi

Re: Python-specific question: variable scope

2007-03-30 Thread Jeremy Dunck
On 3/30/07, Aidas Bendoraitis <[EMAIL PROTECTED]> wrote: ... > 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 ac

Re: Python-specific question: variable scope

2007-03-30 Thread Aidas Bendoraitis
Maybe this leads to nothing and is more-or-less a theoretical question, but anyway, I'll give you another example: a1.py x = "A1" import b a2.py x = "A2" import b b.py - # the module which imports me is a blackbox to me def get_the_x_of_the_module_which_is_importing_me

Re: Python-specific question: variable scope

2007-03-30 Thread Rubic
b.py: import a ... def test(): print a.x -- Jeff Bauer Rubicon, Inc. On Mar 30, 6:43 am, "Aidas Bendoraitis" <[EMAIL PROTECTED]> 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: > ---

Re: Python-specific question: variable scope

2007-03-30 Thread Aidas Bendoraitis
Actually the was no circular import since I haven't imported a from b, but just b from a. And unfortunately your answer didn't solve the original question, which is getting the value from the module that imports the current module. Or maybe the is a way to include another file and parse it with t

Re: Python-specific question: variable scope

2007-03-30 Thread Forest Bond
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 t

Python-specific question: variable scope

2007-03-30 Thread Aidas Bendoraitis
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