Re: Another dumb scope question for a closure.

2008-01-10 Thread Fredrik Lundh
Steven W. Orr wrote: > The problem only happens if I try to modify jj. It only happens if you try to *bind* the name "jj" to an object inside the function. > What am I not understanding? My guess is that you have a C/C++ view of variables and values, where variables are locations in memory th

Re: Another dumb scope question for a closure.

2008-01-10 Thread Steven W. Orr
On Wednesday, Jan 9th 2008 at 14:01 -, quoth Fredrik Lundh: =>Steven W. Orr wrote: => =>> So sorry because I know I'm doing something wrong. =>> =>> 574 > cat c2.py =>> #! /usr/local/bin/python2.4 =>> =>> def inc(jj): =>> def dummy(): =>> jj = jj + 1 =>> return jj =>>

Re: Another dumb scope question for a closure.

2008-01-09 Thread Waldemar Osuch
On Jan 9, 3:52 pm, Waldemar Osuch <[EMAIL PROTECTED]> wrote: > On Jan 9, 11:47 am, "Steven W. Orr" <[EMAIL PROTECTED]> wrote: > > > > > So sorry because I know I'm doing something wrong. > > > 574 > cat c2.py > > #! /usr/local/bin/python2.4 > > > def inc(jj): > > def dummy(): > > jj =

Re: Another dumb scope question for a closure.

2008-01-09 Thread Waldemar Osuch
On Jan 9, 11:47 am, "Steven W. Orr" <[EMAIL PROTECTED]> wrote: > So sorry because I know I'm doing something wrong. > > 574 > cat c2.py > #! /usr/local/bin/python2.4 > > def inc(jj): > def dummy(): > jj = jj + 1 > return jj > return dummy > > h = inc(33) > print 'h() = '

Re: Another dumb scope question for a closure.

2008-01-09 Thread Fredrik Lundh
Ben Fisher wrote: > One way to get this to work is: > > def inc(jj): > def dummy(jj = jj): > jj = jj + 1 > return jj > return dummy > > h = inc(33) > print h() > > It's not very pretty though, especially when you have many variables > you want to have in

Re: Another dumb scope question for a closure.

2008-01-09 Thread Arnaud Delobelle
On Jan 9, 8:24 pm, Mike Meyer <[EMAIL PROTECTED]> wrote: > On Wed, 9 Jan 2008 13:47:30 -0500 (EST) "Steven W. Orr" <[EMAIL PROTECTED]> > wrote: > > > > > So sorry because I know I'm doing something wrong. > > > 574 > cat c2.py > > #! /usr/local/bin/python2.4 > > > def inc(jj): > >      def dummy()

Re: Another dumb scope question for a closure.

2008-01-09 Thread Ben Fisher
One way to get this to work is: def inc(jj): def dummy(jj = jj): jj = jj + 1 return jj return dummy h = inc(33) print h() It's not very pretty though, especially when you have many variables you want to have in the inner scope. -Ben On 1/9/08, Mi

Re: Another dumb scope question for a closure.

2008-01-09 Thread Mike Meyer
On Wed, 9 Jan 2008 13:47:30 -0500 (EST) "Steven W. Orr" <[EMAIL PROTECTED]> wrote: > So sorry because I know I'm doing something wrong. > > 574 > cat c2.py > #! /usr/local/bin/python2.4 > > def inc(jj): > def dummy(): > jj = jj + 1 > return jj > return dummy > > h =

Re: Another dumb scope question for a closure.

2008-01-09 Thread Fredrik Lundh
Steven W. Orr wrote: > So sorry because I know I'm doing something wrong. > > 574 > cat c2.py > #! /usr/local/bin/python2.4 > > def inc(jj): > def dummy(): > jj = jj + 1 > return jj > return dummy > > h = inc(33) > print 'h() = ', h() > 575 > c2.py > h() = > Tracebac

Another dumb scope question for a closure.

2008-01-09 Thread Steven W. Orr
So sorry because I know I'm doing something wrong. 574 > cat c2.py #! /usr/local/bin/python2.4 def inc(jj): def dummy(): jj = jj + 1 return jj return dummy h = inc(33) print 'h() = ', h() 575 > c2.py h() = Traceback (most recent call last): File "./c2.py", line 10,