[Python-ideas] Where-statement (Proposal for function expressions)

Daniel Stutzbach daniel at stutzbachenterprises.com
Fri Jul 17 10:20:08 CEST 2009


On Thu, Jul 16, 2009 at 9:02 PM, Greg Ewing <greg.ewing at canterbury.ac.nz>wrote:

> I would expect x to be bound in the current scope,
> not the where-block scope. But I would expect
>
>  x[i] = 5 where:
>    x = y
>    i = 7
>
> to be equivalent to
>
>  y[7] = 5
>

How about if attempts to re-bind variables in outer scopes should throw an
exception?  Much like they already do in this example:

>>> x = 5
>>> def foo():
...   blah = x
...   x = 6
...
>>> foo()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in foo
UnboundLocalError: local variable 'x' referenced before assignment

(rebinding is allowed if "global" or "nonlocal" is explicitly used, of
course)

--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090717/134bf994/attachment.html>


More information about the Python-ideas mailing list