Re: Python scope is too complicated

2005-03-21 Thread Greg Ewing
jfj wrote: def foo(x): y= (i for i in x) return y From the disassembly it seems that the generator is a code object but 'x' is not a cell variable. WTF? That's because x is not assigned to anywhere in the body of foo. The bytecode compiler optimizes away the creation of a cell in this ca

Re: Python scope is too complicated

2005-03-21 Thread Terry Reedy
"jfj" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > def foo(x): > y= (i for i in x) > return y > > From the disassembly it seems that the generator is a code object What is type(foo([1,2,3])) ? > but 'x' is not a cell variable. WTF? As I understand it, the object 'x' b

Re: Python scope is too complicated

2005-03-21 Thread jfj
Dan Bishop wrote: x = 17 sum(x for x in xrange(101)) 5050 x 17 Your example with generator expressions is interesting. Even more interesting is: def foo(x): y= (i for i in x) return y From the disassembly it seems that the generator is a code object but 'x' is not a cell variable. WTF?

Re: Python scope is too complicated

2005-03-20 Thread Ivan Van Laningham
Hi All-- Dan Bishop wrote: > > > """In Python, there are only two scopes. The global and the local. > > The global scope is a dictionary while the local, in the case of a > > function is extremely fast. There are no other scopes. > > This isn't true anymore, now that generator comprehensions h

Re: Python scope is too complicated

2005-03-20 Thread Dan Bishop
jfj wrote: > Max wrote: > > Yeah, I know. It's the price we pay for forsaking variable declarations. > > But for java programmers like me, Py's scoping is too complicated. > > Please explain what constitutes a block/namespace, and how to refer to > > variables outside of it. > > > Some may disagree

Re: Python scope is too complicated

2005-03-20 Thread jfj
Max wrote: Yeah, I know. It's the price we pay for forsaking variable declarations. But for java programmers like me, Py's scoping is too complicated. Please explain what constitutes a block/namespace, and how to refer to variables outside of it. Some may disagree, but for me the easiest way to

Re: Python scope is too complicated

2005-03-20 Thread TZOTZIOY
On Sun, 20 Mar 2005 13:53:34 +0200, rumours say that Max <[EMAIL PROTECTED]> might have written: >Yeah, I know. It's the price we pay for forsaking variable declarations. >But for java programmers like me, Py's scoping is too complicated. >Please explain what constitutes a block/namespace, and h

Python scope is too complicated

2005-03-20 Thread Max
Yeah, I know. It's the price we pay for forsaking variable declarations. But for java programmers like me, Py's scoping is too complicated. Please explain what constitutes a block/namespace, and how to refer to variables outside of it. -- http://mail.python.org/mailman/listinfo/python-list