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 class.x due to inheritance rules. Consider one example: example snipped see thread/

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-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 Code:

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 + y

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

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

2010-02-25 Thread Arnaud Delobelle
dontspamleo dontsendleos...@gmail.com 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

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: type 'exceptions.NameError': global name 'j' is not defined Which Python implementation are you

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

2010-02-24 Thread b3ng0
On Feb 24, 5:52 am, Nomen Nescio nob...@dizum.com 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: type 'exceptions.NameError': global name 'j' is not

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 al...@start.no 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: type

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: type 'exceptions.NameError': global name 'j' is not defined It's due to scoping rules for

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

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

2010-02-24 Thread Arnaud Delobelle
dontspamleo dontsendleos...@gmail.com 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: