]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add NamedTuple
authorAndrew M. Kuchling <amk@amk.ca>
Thu, 1 Mar 2007 14:36:12 +0000 (14:36 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Thu, 1 Mar 2007 14:36:12 +0000 (14:36 +0000)
Doc/whatsnew/whatsnew26.tex

index fe0a6dde4ee0e03fa20d9d70463a5d64bc32c1bd..d341155e7addb07607e9c8240b3d97e08278f97d 100644 (file)
@@ -76,6 +76,22 @@ details.
 
 \begin{itemize}
 
+\item New data type in the \module{collections} module:
+\class{NamedTuple(\var{typename}, \var{fieldnames})} is a factory function that
+creates subclasses of the standard tuple whose fields are accessible
+by name as well as index.  For example:
+
+\begin{verbatim}
+var_type = collections.NamedTuple('variable', 
+             'id name type size')
+var = var_type(1, 'frequency', 'int', 4)
+
+print var[0], var.id           # Equivalent
+print var[2], var.type          # Equivalent
+\end{verbatim}
+
+(Contributed by Raymond Hettinger.)
+
 \item New function in the \module{heapq} module:
 \function{merge(iter1, iter2, ...)} 
 takes any number of iterables that return data