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
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 ex
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 Purdie wrote:
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
En Wed, 11 Nov 2009 11:11:31 -0300, Ralax escribió:
On Nov 11, 6:59 pm, Richard Purdie wrote:
def B():
os.stat("/")
import os
Traceback (most recent call last):
File "./test.py", line 12, in
B()
File "./test.py", line 8, in B
os.stat("/")
UnboundLocalError: local variab
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 :(.
> > What I'm trying to do is to avoid having "import
On Nov 11, 6:59 pm, Richard Purdie 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
>
>
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.
> What I'm trying to do is to avoid having "import X" statements
> everywhere by changing __builtin__. It seems my approach does
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
On Wed, Nov 11, 2009 at 8:49 AM, Eduardo Lenz 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():
>> >
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__.o
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 (mo
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
12 matches
Mail list logo