Re: confusing UnboundLocalError behaive

2009-02-23 Thread Steven D'Aprano
On Mon, 23 Feb 2009 00:06:58 -0800, neoedmund wrote: > see the 3 small piece of code, i cannot understand why it result as > this. > > 1. > def test(): > abc="111" > def m1(): > print(abc) > m1() > test() > > Output: 111 abc is local to test(). print(abc) looks f

Re: confusing UnboundLocalError behaive

2009-02-23 Thread Gabriel Genellina
En Mon, 23 Feb 2009 06:06:58 -0200, neoedmund escribió: it seems "you cannot change the outter scope values but can use it readonly." Exactly. Python doesn't have variable "declarations" - so the compiler uses this rule: "if the variable is assigned to, anywhere in the function body, it's

Re: confusing UnboundLocalError behaive

2009-02-23 Thread Chris Rebert
On Mon, Feb 23, 2009 at 12:06 AM, neoedmund wrote: > see the 3 small piece of code, i cannot understand why it result as > this. > > 1. > def test(): >abc="111" >def m1(): >print(abc) >m1() > test() > > Output: 111 > > 2. > def test(): >abc="111" >

confusing UnboundLocalError behaive

2009-02-23 Thread neoedmund
see the 3 small piece of code, i cannot understand why it result as this. 1. def test(): abc="111" def m1(): print(abc) m1() test() Output: 111 2. def test(): abc="111" def m1(): print(abc) abc+="222"