8000 Convert 10 PEPs to reSt (#180) · python/peps@87dc92a · GitHub
[go: up one dir, main page]

Skip to content

Commit 87dc92a

Browse files
Mariattabrettcannon
authored andcommitted
Convert 10 PEPs to reSt (#180)
1 parent fdc405d commit 87dc92a

10 files changed

+1259
-1103
lines changed

pep-0212.txt

Lines changed: 106 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -5,163 +5,180 @@ Last-Modified: $Date$
55
Author: nowonder@nowonder.de (Peter Schneider-Kamp)
66
Status: Deferred
77
Type: Standards Track
8+
Content-Type: text/x-rst
89
Created: 22-Aug-2000
910
Python-Version: 2.1
1011
Post-History:
1112

1213

1314
Introduction
15+
============
1416

15-
This PEP describes the often proposed feature of exposing the loop
16-
counter in for-loops. This PEP tracks the status and ownership of
17-
this feature. It contains a description of the feature and
18-
outlines changes necessary to support the feature. This PEP
19-
summarizes discussions held in mailing list forums, and provides
20-
URLs for further information, where appropriate. The CVS revision
21-
history of this file contains the definitive historical record.
17+
This PEP describes the often proposed feature of exposing the loop
18+
counter in for-loops. This PEP tracks the status and ownership of
19+
this feature. It contains a description of the feature and
20+
outlines changes necessary to support the feature. This PEP
21+
summarizes discussions held in mailing list forums, and provides
22+
URLs for further information, where appropriate. The CVS revision
23+
history of this file contains the definitive historical record.
2224

2325

2426
Motivation
27+
==========
2528

26-
Standard for-loops in Python iterate over the elements of a
27-
sequence[1]. Often it is desirable to loop over the indices or
28-
both the elements and the indices instead.
29+
Standard for-loops in Python iterate over the elements of a
30+
sequence [1]_. Often it is desirable to loop over the indices or
31+
both the elements and the indices instead.
2932

30-
The common idioms used to accomplish this are unintuitive. This
31-
PEP proposes two different ways of exposing the indices.
33+
The common idioms used to accomplish this are unintuitive. This
34+
PEP proposes two different ways of exposing the indices.
3235

3336

3437
Loop counter iteration
38+
======================
3539

36-
The current idiom for looping over the indices makes use of the
37-
built-in 'range' function:
40+
The current idiom for looping over the indices makes use of the
41+
built-in ``range`` function::
3842

39-
for i in range(len(sequence)):
40-
# work with index i
43+
for i in range(len(sequence)):
44+
# work with index i
4145

42-
Looping over both elements and indices can be achieved either by the
43-
old idiom or by using the new 'zip' built-in function[2]:
46+
Looping over both elements and indices can be achieved either by the
47+
old idiom or by using the new ``zip`` built-in function [2]_::
4448

45-
for i in range(len(sequence)):
46-
e = sequence[i]
47-
# work with index i and element e
49+
for i in range(len(sequence)):
50+
e = sequence[i]
51+
# work with index i and element e
4852

49-
or
53+
or::
5054

51-
for i, e in zip(range(len(sequence)), sequence):
52-
# work with index i and element e
55+
for i, e in zip(range(len(sequence)), sequence):
56+
# work with index i and element e
5357

5458

5559
The Proposed Solutions
60+
======================
5661

57-
There are three solutions that have been discussed. One adds a
58-
non-reserved keyword, the other adds two built-in functions.
59-
A third solution adds methods to sequence objects.
62+
There are three solutions that have been discussed. One adds a
63+
non-reserved keyword, the other adds two built-in functions.
64+
A third solution adds methods to sequence objects.
6065

6166

62-
Non-reserved keyword 'indexing'
67+
Non-reserved keyword ``indexing``
68+
=================================
6369

64-
This solution would extend the syntax of the for-loop by adding
65-
an optional '<variable> indexing' clause which can also be used
66-
instead of the '<variable> in' clause..
70+
This solution would extend the syntax of the for-loop by adding
71+
an optional ``<variable> indexing`` clause which can also be used
72+
instead of the ``<variable> in`` clause.
6773

68-
Looping over the indices of a sequence would thus become:
74+
Looping over the indices of a sequence would thus become::
6975

70-
for i indexing sequence:
71-
# work with index i
76+
for i indexing sequence:
77+
# work with index i
7278

73-
Looping over both indices and elements would similarly be:
79+
Looping over both indices and elements would similarly be::
7480

75-
for i indexing e in sequence:
76-
# work with index i and element e
81+
for i indexing e in sequence:
82+
# work with index i and element e
7783

7884

79-
Built-in functions 'indices' and 'irange'
85+
Built-in functions ``indices`` and ``irange``
86+
=============================================
8087

81-
This solution adds two built-in functions 'indices' and 'irange'.
82-
The semantics of these can be described as follows:
88+
This solution adds two built-in functions ``indices`` and ``irange``.
89+
The semantics of these can be described as follows::
8390

84-
def indices(sequence):
85-
return range(len(sequence))
91+
def indices(sequence):
92+
return range(len(sequence))
8693

87-
def irange(sequence):
88-
return zip(range(len(sequence)), sequence)
94+
def irange(sequence):
95+
return zip(range(len(sequence)), sequence)
8996

90-
These functions could be implemented either eagerly or lazily and
91-
should be easy to extend in order to accept more than one sequence
92-
argument.
97+
These functions could be implemented either eagerly or lazily and
98+
should be easy to extend in order to accept more than one sequence
99+
argument.
93100

94-
The use of these functions would simplify the idioms for looping
95-
over the indices and over both elements and indices:
101+
The use of these functions would simplify the idioms for looping
102+
over the indices and over both elements and indices::
96103

97-
for i in indices(sequence):
98-
# work with index i
104+
for i in indices(sequence):
105+
# work with index i
99106

100-
for i, e in irange(sequence):
101-
# work with index i and element e
107+
for i, e in irange(sequence):
108+
# work with index i and element e
102109

103110

104111
Methods for sequence objects
112+
============================
105113

106-
This solution proposes the addition of 'indices', 'items'
107-
and 'values' methods to sequences, which enable looping over
108-
indices only, both indices and elements, and elements only
109-
respectively.
114+
This solution proposes the addition of ``indices``, ``items``
115+
and ``values`` methods to sequences, which enable looping over
116+
indices only, both indices and elements, and elements only
117+
respectively.
110118

111-
This would immensely simplify the idioms for looping over indices
112-
and for looping over both elements and indices:
119+
This would immensely simplify the idioms for looping over indices
120+
and for looping over both elements and indices::
113121

114-
for i in sequence.indices():
115-
# work with index i
122+
for i in sequence.indices():
123+
# work with index i
116124

117-
for i, e in sequence.items():
118-
# work with index i and element e
125+
for i, e in sequence.items():
126+
# work with index i and element e
119127

120-
Additionally it would allow to do looping over the elements
121-
of sequences and dicitionaries in a consistent way:
128+
Additionally it would allow to do looping over the elements
129+
of sequences and dictionaries in a consistent way::
122130

123-
for e in sequence_or_dict.values():
124-
# do something with element e
131+
for e in sequence_or_dict.values():
132+
# do something with element e
125133

126134

127135
Implementations
136+
===============
128137

129-
For all three solutions some more or less rough patches exist
130-
as patches at SourceForge:
138+
For all three solutions some more or less rough patches exist
139+
as patches at SourceForge:
131140

132-
'for i indexing a in l': exposing the for-loop counter[3]
133-
add indices() and irange() to built-ins[4]
134-
add items() method to listobject[5]
141+
- ``for i indexing a in l``: exposing the for-loop counter [3]_
142+
- add ``indices()`` and ``irange()`` to built-ins [4]_
143+
- add ``items()`` method to listobject [5]_
135144

136-
All of them have been pronounced on and rejected by the BDFL.
145+
All of them have been pronounced on and rejected by the BDFL.
137146

138-
Note that the 'indexing' keyword is only a NAME in the
139-
grammar and so does not hinder the general use of 'indexing'.
147+
Note that the ``indexing`` keyword is only a ``NAME`` in the
148+
grammar and so does not hinder the general use of ``indexing``.
140149

141150

142151
Backward Compatibility Issues
152+
=============================
143153

144-
As no keywords are added and the semantics of existing code
145-
remains unchanged, all three solutions can be implemented
146-
without breaking existing code.
154+
As no keywords are added and the semantics of existing code
155+
remains unchanged, all three solutions can be implemented
156+
without breaking existing code.
147157

148158

149159
Copyright
160+
=========
150161

151-
This document has been placed in the public domain.
162+
This document has been placed in the public domain.
152163

153164

154165
References
166+
==========
155167

156-
[1] http://docs.python.org/reference/compound_stmts.html#for
157-
[2] Lockstep Iteration, PEP 201
158-
[3] http://sourceforge.net/patch/download.php?id=101138
159-
[4] http://sourceforge.net/patch/download.php?id=101129
160-
[5] http://sourceforge.net/patch/download.php?id=101178
168+
.. [1] http://docs.python.org/reference/compound_stmts.html#for
161169

170+
.. [2] Lockstep Iteration, PEP 201
162171

163-
164-
Local Variables:
165-
mode: indented-text
166-
indent-tabs-mode: nil
167-
End:
172+
.. [3] http://sourceforge.net/patch/download.php?id=101138
173+
174+
.. [4] http://sourceforge.net/patch/download.php?id=101129
175+
176+
.. [5] http://sourceforge.net/patch/download.php?id=101178
177+
178+
179+
180+
..
181+
Local Variables:
182+
mode: indented-text
183+
indent-tabs-mode: nil
184+
End:

0 commit comments

Comments
 (0)
0