[IronPython] Hosting IronPython 2.X in .NET app
M. David Peterson
xmlhacker at gmail.com
Tue Jul 10 22:15:07 CEST 2007
On 7/10/07, Jacob Lee <t-jlee at microsoft.com> wrote:
>
>
> Closures have existed in Python since version 2.1 or so:
> def f():
> x = 5
> return lambda: x
> closure = f()
> print closure() # prints 5
>
> Here, the anonymous inner function returned by f is able to refer to
> variables defined in outer scopes.
Oh, nice! This is did not know. So then are closures available now in IP?
As for the Python 3000 question --
> The one current limitation is that you cannot rebind names defined in
> outer scopes.
To me that's a feature, not a limitation. ;-)
That is, the following code does not work as expected:
>
> def f():
> x = 5
> def g():
> x = 7 # x is local to g here
>
> You could use the "global" statement to indicate that x is a global
> despite it being assigned to inside the function, but there was no
> equivalent way to indicate that x refers to a variable in an outer, but
> non-global, scope. Python 3000 will introduce the "nonlocal" statement that
> works like the global statement to fill this gap. As usual, the best source
> is the relevant PEP: http://www.python.org/dev/peps/pep-3104/
>
> Hope this helps.
It does. Thanks!
--
/M:D
M. David Peterson
http://mdavid.name | http://www.oreillynet.com/pub/au/2354 |
http://dev.aol.com/blog/3155
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20070710/6f76cf7e/attachment.html>
More information about the Ironpython-users
mailing list