mirror of https://github.com/python/cpython
Put code examples at left margin instead of indenting them
This commit is contained in:
parent
7af1bdf619
commit
4732c6e164
|
@ -360,20 +360,20 @@ Setting the \member{default_factory} to \class{set} makes the
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> Point = NamedTuple('Point', 'x y')
|
>>> Point = NamedTuple('Point', 'x y')
|
||||||
>>> Point.__doc__ # docstring for the new datatype
|
>>> Point.__doc__ # docstring for the new datatype
|
||||||
'Point(x, y)'
|
'Point(x, y)'
|
||||||
>>> p = Point(11, y=22) # instantiate with positional or keyword arguments
|
>>> p = Point(11, y=22) # instantiate with positional or keyword arguments
|
||||||
>>> p[0] + p[1] # works just like the tuple (11, 22)
|
>>> p[0] + p[1] # works just like the tuple (11, 22)
|
||||||
33
|
33
|
||||||
>>> x, y = p # unpacks just like a tuple
|
>>> x, y = p # unpacks just like a tuple
|
||||||
>>> x, y
|
>>> x, y
|
||||||
(11, 22)
|
(11, 22)
|
||||||
>>> p.x + p.y # fields also accessable by name
|
>>> p.x + p.y # fields also accessable by name
|
||||||
33
|
33
|
||||||
>>> p # readable __repr__ with name=value style
|
>>> p # readable __repr__ with name=value style
|
||||||
Point(x=11, y=22)
|
Point(x=11, y=22)
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
|
||||||
The use cases are the same as those for tuples. The named factories
|
The use cases are the same as those for tuples. The named factories
|
||||||
assign meaning to each tuple position and allow for more readable,
|
assign meaning to each tuple position and allow for more readable,
|
||||||
|
@ -382,10 +382,10 @@ Setting the \member{default_factory} to \class{set} makes the
|
||||||
returned by the \module{csv} or \module{sqlite3} modules. For example:
|
returned by the \module{csv} or \module{sqlite3} modules. For example:
|
||||||
|
|
||||||
\begin{verbatim}
|
\begin{verbatim}
|
||||||
import csv
|
import csv
|
||||||
EmployeeRecord = NamedTuple('EmployeeRecord', 'name age title department paygrade')
|
EmployeeRecord = NamedTuple('EmployeeRecord', 'name age title department paygrade')
|
||||||
for tup in csv.reader(open("employees.csv", "rb")):
|
for tup in csv.reader(open("employees.csv", "rb")):
|
||||||
print EmployeeRecord(*tup)
|
print EmployeeRecord(*tup)
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
Loading…
Reference in New Issue