Re: Confused by Python and nested scoping (2.4.3)

2006-04-20 Thread BartlebyScrivener
>> P.S. I have just noticed that Terry Jan Reedy answered >> similarly. Never mind... Repeat, repeat, repeat until >> you know ;) Yes, and some of us appreciate the extra examples. rick -- http://mail.python.org/mailman/listinfo/python-list

Re: Confused by Python and nested scoping (2.4.3)

2006-04-20 Thread Kent Johnson
Kelvie Wong wrote: > There are only two scopes in Python -- global scope and function scope. No, Python has local, nested, global and built-in scope. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Confused by Python and nested scoping (2.4.3)

2006-04-20 Thread Petr Prikryl
I have added some spaces guessing how the original was formatted. See the simplified example and the explanation below... "Sean Givan" wrote... > Hi. I'm new to Python [...] something strange. > This code: > > def outer(): > val = 10 > def inner(): > print val > inner() > outer() > > ..pr

Re: Confused by Python and nested scoping (2.4.3)

2006-04-19 Thread Fredrik Lundh
Sean Givan wrote: > Hi. I'm new to Python, and downloaded a Windows copy a little while > ago. I was doing some experiments with nested functions, and ran into > something strange. > > This code: > > def outer(): > val = 10 > def inner(): > print val > inner() > > outer() > > ..prints out the va

Re: Confused by Python and nested scoping (2.4.3)

2006-04-19 Thread Terry Reedy
"Sean Givan" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi. I'm new to Python, and downloaded a Windows copy a little while > ago. I was doing some experiments with nested functions, and ran into > something strange. Experiments are good. Strange can be instructive. ... > I'

Re: Confused by Python and nested scoping (2.4.3)

2006-04-19 Thread Schüle Daniel
Sean Givan schrieb: > Hi. I'm new to Python welcome > ago. I was doing some experiments with nested functions, and ran into > something strange. > > This code: > > def outer(): > val = 10 > def inner(): > print val > inner() > > outer() > > ...prints out the value '10',

Re: Confused by Python and nested scoping (2.4.3)

2006-04-19 Thread Ben Cartwright
Sean Givan wrote: > def outer(): > val = 10 > def inner(): > print val > val = 20 > inner() > print val > > outer() > > ..I expected to print '10', then '20', but instead got an error: > >print val > UnboundLocalError: local variable 'val' ref

Re: Confused by Python and nested scoping (2.4.3)

2006-04-19 Thread Kelvie Wong
There are only two scopes in Python -- global scope and function scope. On 4/19/06, Sean Givan <[EMAIL PROTECTED]> wrote: > Hi. I'm new to Python, and downloaded a Windows copy a little while > ago. I was doing some experiments with nested functions, and ran into > something strange. > > This co

Confused by Python and nested scoping (2.4.3)

2006-04-19 Thread Sean Givan
Hi. I'm new to Python, and downloaded a Windows copy a little while ago. I was doing some experiments with nested functions, and ran into something strange. This code: def outer(): val = 10 def inner(): print val inner() outer() ..prints out the value