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): Fi

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 = 1

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 wrote: > > > Is there a way to make the "global x" apply to all functions without > > adding it to each one? > > Thankfully, no. Hmm :(. > >