On Tue, 15 Jun 2010 17:12:47 -0700, Inyeol Lee wrote:
> > "execfile() cannot be used reliably to modify a function’s locals."
[...]
> This is due to CPython's static optimization of local name lookup. Dummy
> 'exec' statement disables this and makes your example work:
>
> def X():
> exec "None"
On Tue, 15 Jun 2010 15:22:17 -0700, Peter wrote:
> I checked help on execfile and could only find the following
> (mystifying) sentence:
>
> "execfile() cannot be used reliably to modify a function’s locals."
What is mystifying about it? It's short and clear -- execfile cannot be
used to reliab
Inyeol Lee wrote:
> On Jun 15, 3:22 pm, Peter wrote:
>> I am puzzled by what appears to be a scope issue - obviously I have
>> something wrong :-)
>>
>> Why does this work:
>>
>> if __name__ == 'main':
>> execfile('test-data.py')
>> print data
>>
>> and yet this doesn't (I get "NameError: global
This one seems to do the trick - thanks! :-)
On Jun 16, 10:12 am, Inyeol Lee wrote:
> On Jun 15, 3:22 pm, Peter wrote:
>
>
>
>
>
> > I am puzzled by what appears to be a scope issue - obviously I have
> > something wrong :-)
>
> > Why does this work:
>
> > if __name__ == 'main':
> > execfile('
On Jun 15, 3:22 pm, Peter wrote:
> I am puzzled by what appears to be a scope issue - obviously I have
> something wrong :-)
>
> Why does this work:
>
> if __name__ == 'main':
> execfile('test-data.py')
> print data
>
> and yet this doesn't (I get "NameError: global name 'data' not
> defined")
Peter wrote:
I am puzzled by what appears to be a scope issue - obviously I have
something wrong :-)
Why does this work:
if __name__ == 'main':
execfile('test-data.py')
print data
and yet this doesn't (I get "NameError: global name 'data' not
defined"):
def X():
execfile('test-data.py')
John,
Thanks for writing, and I'm sorry it's taken so long to get back to you. Python
is fun for me -- dinner guests and my boss got in the way.
>> The code ... is the result of noodling around with switches as a learning
>> tool. I've played with python for a few years, but I'm self-taught, so
[EMAIL PROTECTED] wrote:
> The code that follows is the result of noodling around with switches as a
> learning tool. I've played with python for a few years, but I'm self-taught,
> so . . .
>
> Class Switch builds a set of functions. Method switch executes one of them
> given a value of the sw
On 2007-08-06, Nitro <[EMAIL PROTECTED]> wrote:
> Hello,
>
> today I wrote this piece of code and I am wondering why it does
> not work the way I expect it to work. Here's the code:
>
> y = 0
> def func():
> y += 3
> func()
>
> This gives an
>
> UnboundLocalError: local variable 'y' reference
Thanks a lot for clearing this up, Diez!
-Matthias
--
http://mail.python.org/mailman/listinfo/python-list
Nitro wrote:
> Hello,
>
> today I wrote this piece of code and I am wondering why it does not work
> the way I expect it to work. Here's the code:
>
> y = 0
> def func():
> y += 3
> func()
>
> This gives an
>
> UnboundLocalError: local variable 'y' referenced before assignment
>
> If I c
11 matches
Mail list logo