[Python-checkins] CVS: python/nondist/peps pep-0279.txt,1.3,1.4
Barry Warsaw
bwarsaw@users.sourceforge.net
Thu, 07 Feb 2002 04:08:14 -0800
Update of /cvsroot/python/python/nondist/peps
In directory usw-pr-cvs1:/tmp/cvs-serv21255
Modified Files:
pep-0279.txt
Log Message:
Raymond Hettinger's latest update, slightly reformatted.
Index: pep-0279.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep-0279.txt,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** pep-0279.txt 4 Feb 2002 21:03:03 -0000 1.3
--- pep-0279.txt 7 Feb 2002 12:08:12 -0000 1.4
***************
*** 61,64 ****
--- 61,69 ----
generators become final and are not imported from __future__.
+ SourceForge contains a working, pure Python simulation of every
+ feature proposed in this PEP [8]. SourceForge also has a separate
+ file with a simulation test suite and working source code for the
+ examples listed used in this PEP [9].
+
Specification for new built-ins:
***************
*** 119,123 ****
yield fun(*args)
! def xzip( *collections ):
'''
xzip(...)
--- 124,128 ----
yield fun(*args)
! def xzip( *collections ): ### Code from Python Cookbook [6]
'''
xzip(...)
***************
*** 147,150 ****
--- 152,161 ----
not include generators.
+ Note B: An alternate, simplified definition of indexed was proposed:
+
+ def indexed( collection, cnt=0, limit=sys.maxint ):
+ 'Generates an indexed series: (0,seqn[0]), (1,seqn[1]) ...'
+ return xzip( xrange(cnt,limit), collection )
+
Specification for Generator Comprehensions:
***************
*** 178,181 ****
--- 189,223 ----
in fact helpful.
+ Note B: An iterable instance is returned by the above code. The
+ purpose is to allow the object to be re-started and looped-over
+ multiple times. This accurately mimics the behavior of list
+ comprehensions. As a result, the following code (provided by Oren
+ Tirosh) works equally well with or without 'yield':
+
+ letters = [yield chr(i) for i in xrange(ord('a'),ord('z')+1)]
+ digits = [yield str(i) for i in xrange(10)]
+ letdig = [yield l+d for l in letters for d in digits]
+
+ Note C: List comprehensions expose their looping variable and
+ leave the variable in the enclosing scope. The code, [str(i) for
+ i in range(8)] leaves 'i' set to 7 in the scope where the
+ comprehension appears. This behavior is by design and reflects an
+ intent to duplicate the result of coding a for-loop instead of a
+ list comprehension. Further, the variable 'i' is in a defined and
+ potentially useful state on the line immediately following the
+ list comprehension.
+
+ In contrast, generator comprehensions do not expose the looping
+ variable to the enclosing scope. The code, [yield str(i) for i in
+ range(8)] leaves 'i' untouched in the scope where the
+ comprehension appears. This is also by design and reflects an
+ intent to duplicate the result of coding a generator directly
+ instead of a generator comprehension. Further, the variable 'i'
+ is not in a defined state on the line immediately following the
+ list comprehension. It does not come into existence until
+ iteration starts. Since several generators may be running at
+ once, there are potentially multiple, unequal instances of 'i' at
+ any one time.
+
Specification for Generator Parameter Passing:
***************
*** 260,271 ****
Loop over the picture files in a directory, shrink them
! one-at-a-time to thumbnail size using PIL, and send them to a lazy
! consumer. That consumer is responsible for creating a large blank
! image, accepting thumbnails one-at-a-time and placing them in a
! 5x3 grid format onto the blank image. Whenever the grid is full,
! it writes-out the large image as an index print. A FlushStream
! exception indicates that no more thumbnails are available and that
! the partial index print should be written out if there are one or
! more thumbnails on it.
--- 302,313 ----
Loop over the picture files in a directory, shrink them
! one-at-a-time to thumbnail size using PIL [7], and send them to a
! lazy consumer. That consumer is responsible for creating a large
! blank image, accepting thumbnails one-at-a-time and placing them
! in a 5x3 grid format onto the blank image. Whenever the grid is
! full, it writes-out the large image as an index print. A
! FlushStream exception indicates that no more thumbnails are
! available and that the partial index print should be written out
! if there are one or more thumbnails on it.
***************
*** 349,352 ****
--- 391,407 ----
http://gnosis.cx/publish/programming/charming_python_b5.txt
+ [6] The code fragment for xmap() was found at:
+ http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66448
+
+ [7] PIL, the Python Imaging Library can be found at:
+ http://www.pythonware.com/products/pil/
+
+ [8] A pure Python simulation of every feature in this PEP is at:
+ http://sourceforge.net/tracker/download.php?group_id=5470&atid=305470&file_id=17348&aid=513752
+
+ [9] The full, working source code for each of the examples in this PEP
+ along with other examples and tests is at:
+ http://sourceforge.net/tracker/download.php?group_id=5470&atid=305470&file_id=17412&aid=513756
+
Copyright
***************
*** 361,364 ****
fill-column: 70
End:
-
-
--- 416,417 ----