Re: Unexpected python exception

2009-11-17 Thread Andreas Löscher
Hi, unfortunatley I cannot reproduce your error. Which Python Version do you use? The expected case in this scenario is that the exception is thrown, as you import os in A() where it is stored in the local namespace of the function. I tested it with Python 2.4, 2.5 and 2.6 and in both cases an

Re: Unexpected python exception

2009-11-17 Thread Andreas Löscher
Python searches for Variables not only in local or global scoop but also in __builtins__. If you do something like __builtins__.os = os, than this variable should be accessible global. If you then write something like: def B(): os.stat(/) import os Python recognises on compile

Re: Unexpected python exception

2009-11-13 Thread Gabriel Genellina
En Wed, 11 Nov 2009 11:11:31 -0300, Ralax ralaxmys...@gmail.com escribió: On Nov 11, 6:59 pm, Richard Purdie rpur...@rpsys.net wrote: def B(): os.stat(/) import os Traceback (most recent call last): File ./test.py, line 12, in module B() File ./test.py, line 8, in B

Re: Unexpected python exception

2009-11-13 Thread Tino Wildenhain
Am 11.11.2009 15:29, schrieb Richard Purdie: On Wed, 2009-11-11 at 05:04 -0800, Chris Rebert wrote: On Wed, Nov 11, 2009 at 4:37 AM, Richard Purdierpur...@rpsys.net wrote: snip Is there a way to make the global x apply to all functions without adding it to each one? Thankfully, no. Hmm

Unexpected python exception

2009-11-11 Thread Richard Purdie
I've been having problems with an unexpected exception from python which I can summarise with the following testcase: def A(): import __builtin__ import os __builtin__.os = os def B(): os.stat(/) import os A() B() which results in: Traceback (most recent call last):

Re: Unexpected python exception

2009-11-11 Thread Diez B. Roggisch
Richard Purdie schrieb: I've been having problems with an unexpected exception from python which I can summarise with the following testcase: def A(): import __builtin__ import os __builtin__.os = os def B(): os.stat(/) import os A() B() which results in: Traceback

Re: Unexpected python exception

2009-11-11 Thread Eduardo Lenz
Em Qua 11 Nov 2009, às 03:21:55, Diez B. Roggisch escreveu: Richard Purdie schrieb: I've been having problems with an unexpected exception from python which I can summarise with the following testcase: def A(): import __builtin__ import os __builtin__.os = os def

Re: Unexpected python exception

2009-11-11 Thread Chris Rebert
On Wed, Nov 11, 2009 at 8:49 AM, Eduardo Lenz l...@joinville.udesc.br wrote: Em Qua 11 Nov 2009, às 03:21:55, Diez B. Roggisch escreveu: Richard Purdie schrieb: I've been having problems with an unexpected exception from python which I can summarise with the following testcase: def A():

Re: Unexpected python exception

2009-11-11 Thread Richard Purdie
On Wed, 2009-11-11 at 12:21 +0100, Diez B. Roggisch wrote: As the import-statement in a function/method-scope doesn't leak the imported names into the module scope, python treats them as locals. Which makes your code equivalent to x = 1000 def foo(): print x x = 10 Aha,

Re: Unexpected python exception

2009-11-11 Thread Chris Rebert
On Wed, Nov 11, 2009 at 4:37 AM, Richard Purdie rpur...@rpsys.net wrote: snip Is there a way to make the global x apply to all functions without adding it to each one? Thankfully, no. What I'm trying to do is to avoid having import X statements everywhere by changing __builtin__. It seems my

Re: Unexpected python exception

2009-11-11 Thread Ralax
On Nov 11, 6:59 pm, Richard Purdie rpur...@rpsys.net wrote: I've been having problems with an unexpected exception from python which I can summarise with the following testcase: def A():     import __builtin__     import os     __builtin__.os = os def B():     os.stat(/)     import os

Re: Unexpected python exception

2009-11-11 Thread Richard Purdie
On Wed, 2009-11-11 at 05:04 -0800, Chris Rebert wrote: On Wed, Nov 11, 2009 at 4:37 AM, Richard Purdie rpur...@rpsys.net wrote: snip Is there a way to make the global x apply to all functions without adding it to each one? Thankfully, no. Hmm :(. What I'm trying to do is to avoid