Re: scope of generators, class variables, resulting in global na

2010-02-28 Thread dontspamleo
> > ...and really means this... > > class C: > >   x = 1 > >   def f(self,y): return T.x + y > > I don't understand what T is. Did you mean C? Yes, I meant C. Thanks. > > If so, you are wrong. self.x is not the same as .x due to > inheritance rules. Consider one example: > Thanks for the nice e

Re: scope of generators, class variables, resulting in global na

2010-02-27 Thread Steven D'Aprano
On Sat, 27 Feb 2010 15:57:15 -0800, dontspamleo wrote: > I think a big part of the problem is that the scoping rules in Python > are inconsistent because classes are a different kind of object. An > example helps: [...] > But this doesn't work... > class C: > x = 1 > def f(self,y): return x +

Re: scope of generators, class variables, resulting in global na

2010-02-27 Thread sstein...@gmail.com
On Feb 27, 2010, at 6:57 PM, dontspamleo wrote: > > > http://bioscreencastwiki.com/Python_Variable_scope_gymnastics Broken link: Site settings could not be loaded We were unable to locate the API to request site settings. Please see below for debugging information. HTTP Response Status Cod

Re: scope of generators, class variables, resulting in global na

2010-02-27 Thread dontspamleo
I think a big part of the problem is that the scoping rules in Python are inconsistent because classes are a different kind of object. An example helps: This works: x = 1 def f(y): return y + x This works: def f(): x = 1 def g(y): return x + y return g(2) But this doesn't work... class

Re: scope of generators, class variables, resulting in global na

2010-02-25 Thread Arnaud Delobelle
dontspamleo writes: > Hi Arnaud et al, > > Here is the link to the bug report from which the discussion in PEP > 289 was extracted: > > http://bugs.python.org/issue872326 > > It looks like they were fixing a bunch of bugs and that this > discussion was one of the many in that thread. > > Here is

Re: scope of generators, class variables, resulting in global na

2010-02-25 Thread dontspamleo
Hi Arnaud et al, Here is the link to the bug report from which the discussion in PEP 289 was extracted: http://bugs.python.org/issue872326 It looks like they were fixing a bunch of bugs and that this discussion was one of the many in that thread. Here is another post which points to the core of

Re: scope of generators, class variables, resulting in global na

2010-02-24 Thread Arnaud Delobelle
dontspamleo writes: > @Arnaud: I tried to find your earlier post -- googled "Arnaud lambda" > -- but couldn't. I remembered after posting that I sent this to python-ideas. Here is the first message in the thread: http://mail.python.org/pipermail/python-ideas/2007-December/001260.html In this t

Re: scope of generators, class variables, resulting in global na

2010-02-24 Thread dontspamleo
Hi Folks, Thanks everyone for the great contributions! I understand this better now. The distinction between a shorthand for a function definition and a shorthand for a loop iteration is crucial. Also: thanks for pointing out the even the list comprehension doesn't work in py3. That was incredibl

Re: scope of generators, class variables, resulting in global na

2010-02-24 Thread Arnaud Delobelle
Nomen Nescio wrote: > Hello, > > Can someone help me understand what is wrong with this example? > > class T: > A = range(2) > B = range(4) > s = sum(i*j for i in A for j in B) > > It produces the exception: > > : global name 'j' is not defined It's due to scoping rules for classes and/or

Re: scope of generators, class variables, resulting in global na

2010-02-24 Thread Jon Clements
On Feb 24, 12:21 pm, "Alf P. Steinbach" wrote: > * Nomen Nescio: > > > Hello, > > > Can someone help me understand what is wrong with this example? > > > class T: > >   A = range(2) > >   B = range(4) > >   s = sum(i*j for i in A for j in B) > > > It produces the exception: > > > : global name 'j'

Re: scope of generators, class variables, resulting in global na

2010-02-24 Thread b3ng0
On Feb 24, 5:52 am, Nomen Nescio wrote: > Hello, > > Can someone help me understand what is wrong with this example? > > class T: >   A = range(2) >   B = range(4) >   s = sum(i*j for i in A for j in B) > > It produces the exception: > > : global name 'j' is not defined > > The exception above is

Re: scope of generators, class variables, resulting in global na

2010-02-24 Thread Alf P. Steinbach
* Nomen Nescio: Hello, Can someone help me understand what is wrong with this example? class T: A = range(2) B = range(4) s = sum(i*j for i in A for j in B) It produces the exception: : global name 'j' is not defined Which Python implementation are you using? I can't reproduce the er

scope of generators, class variables, resulting in global na

2010-02-24 Thread Nomen Nescio
Hello, Can someone help me understand what is wrong with this example? class T: A = range(2) B = range(4) s = sum(i*j for i in A for j in B) It produces the exception: : global name 'j' is not defined The exception above is especially confusing since the following similar example (I jus