A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2004-March/043469.html below:

[Python-Dev] Possible resolution of generator expression variable capture dilemma

[Python-Dev] Possible resolution of generator expression variable capture dilemma [Python-Dev] Possible resolution of generator expression variable capture dilemmaGuido van Rossum guido at python.org
Wed Mar 24 11:24:43 EST 2004
Phillip shows some examples involving inner functions defined inside
the for loop.  But in current Python these examples work just as well
if the function is defined *outside* the loop (as long as no default
argument values are needed):

> for x in 1,2,3:
>      def y():
>          print z
>      z = x * 2
>      y()

is the same as

  def y():
      print z
  for x in 1, 2, 3:
      z = x*2
      y()

That would change under Phillip's proposal.

There are similar examples that would break under Greg's original
proposal: just use the loop variable in the function, e.g.:

  def y():
      print x*2
  for x in 1, 2, 3:
      y()

All this is just more reason to put this one off until 3.0.

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4