Fred Drake | ed0fa3d | 2003-07-30 19:14:09 +0000 | [diff] [blame] | 1 | \documentclass{howto} |
| 2 | \usepackage{distutils} |
| 3 | % $Id$ |
| 4 | |
| 5 | \title{What's New in Python 2.4} |
| 6 | \release{0.0} |
| 7 | \author{A.M.\ Kuchling} |
| 8 | \authoraddress{\email{amk@amk.ca}} |
| 9 | |
| 10 | \begin{document} |
| 11 | \maketitle |
| 12 | \tableofcontents |
| 13 | |
| 14 | This article explains the new features in Python 2.4. No release date |
| 15 | for Python 2.4 has been set; expect that this will happen in 2004. |
| 16 | |
| 17 | While Python 2.3 was primarily a library development release, Python |
| 18 | 2.4 may extend the core language and interpreter in |
| 19 | as-yet-undetermined ways. |
| 20 | |
| 21 | This article doesn't attempt to provide a complete specification of |
| 22 | the new features, but instead provides a convenient overview. For |
| 23 | full details, you should refer to the documentation for Python 2.4. |
| 24 | % add hyperlink when the documentation becomes available online. |
| 25 | If you want to understand the complete implementation and design |
| 26 | rationale, refer to the PEP for a particular new feature. |
| 27 | |
| 28 | |
| 29 | %====================================================================== |
| 30 | |
| 31 | % Large, PEP-level features and changes should be described here. |
| 32 | |
| 33 | |
| 34 | %====================================================================== |
| 35 | \section{Other Language Changes} |
| 36 | |
| 37 | Here are all of the changes that Python 2.4 makes to the core Python |
| 38 | language. |
| 39 | |
| 40 | \begin{itemize} |
Andrew M. Kuchling | 2fb4d51 | 2003-10-21 12:31:16 +0000 | [diff] [blame^] | 41 | \item The \method{sort()} method of lists gained three keyword |
| 42 | arguments, \var{cmp}, \var{key}, and \var{reverse}. These arguments |
| 43 | make some common usages of \method{sort()} simpler. All are optional. |
| 44 | |
| 45 | \var{cmp} is the same as the previous single argument to |
| 46 | \method{sort()}; if provided, the value should be a comparison |
| 47 | function that takes two arguments and returns -1, 0, or +1 depending |
| 48 | on how the arguments compare. |
| 49 | |
| 50 | \var{key} should be a single-argument function that takes a list |
| 51 | element and returns a comparison key for the element. The list is |
| 52 | then sorted using the comparison keys. The following example sorts a list |
| 53 | case-insensitively: |
| 54 | |
| 55 | \begin{verbatim} |
| 56 | >>> L = ['A', 'b', 'c', 'D'] |
| 57 | >>> L.sort() # Case-sensitive sort |
| 58 | >>> L |
| 59 | ['A', 'D', 'b', 'c'] |
| 60 | >>> L.sort(key=lambda x: x.lower()) |
| 61 | >>> L |
| 62 | ['A', 'b', 'c', 'D'] |
| 63 | >>> L.sort(cmp=lambda x,y: cmp(x.lower(), y.lower())) |
| 64 | >>> L |
| 65 | ['A', 'b', 'c', 'D'] |
| 66 | \end{verbatim} |
| 67 | |
| 68 | The last example, which uses the \var{cmp} parameter, is the old way |
| 69 | to perform a case-insensitive sort. It works, but is slower than |
| 70 | using a \var{key} parameter. Using \var{key} results in calling the |
| 71 | \method{lower()} method once for each element in the list while using |
| 72 | \var{cmp} will call the method twice for each comparison. |
| 73 | |
| 74 | The \var{reverse} parameter should have a Boolean value. If the value is |
| 75 | \constant{True}, the list will be sorted into reverse order. Instead |
| 76 | of \code{L.sort() ; L.reverse()}, you can now write |
| 77 | \code{L.sort(reverse=True)}. |
Fred Drake | ed0fa3d | 2003-07-30 19:14:09 +0000 | [diff] [blame] | 78 | |
| 79 | \end{itemize} |
| 80 | |
| 81 | |
| 82 | %====================================================================== |
| 83 | \subsection{Optimizations} |
| 84 | |
| 85 | \begin{itemize} |
| 86 | |
| 87 | \item Optimizations should be described here. |
| 88 | |
| 89 | \end{itemize} |
| 90 | |
| 91 | The net result of the 2.4 optimizations is that Python 2.4 runs the |
| 92 | pystone benchmark around XX\% faster than Python 2.3 and YY\% faster |
| 93 | than Python 2.2. |
| 94 | |
| 95 | |
| 96 | %====================================================================== |
| 97 | \section{New, Improved, and Deprecated Modules} |
| 98 | |
| 99 | As usual, Python's standard library received a number of enhancements and |
| 100 | bug fixes. Here's a partial list of the most notable changes, sorted |
| 101 | alphabetically by module name. Consult the |
| 102 | \file{Misc/NEWS} file in the source tree for a more |
| 103 | complete list of changes, or look through the CVS logs for all the |
| 104 | details. |
| 105 | |
| 106 | \begin{itemize} |
| 107 | |
Andrew M. Kuchling | 69f31eb | 2003-08-13 23:11:04 +0000 | [diff] [blame] | 108 | \item The \module{curses} modules now supports the ncurses extension |
| 109 | \function{use_default_colors()}. On platforms where the terminal |
| 110 | supports transparency, this makes it possible to use a transparent background. |
| 111 | (Contributed by J\"org Lehmann.) |
| 112 | |
Fred Drake | ed0fa3d | 2003-07-30 19:14:09 +0000 | [diff] [blame] | 113 | \end{itemize} |
| 114 | |
| 115 | |
| 116 | %====================================================================== |
| 117 | % whole new modules get described in \subsections here |
| 118 | |
| 119 | |
| 120 | % ====================================================================== |
| 121 | \section{Build and C API Changes} |
| 122 | |
| 123 | Changes to Python's build process and to the C API include: |
| 124 | |
| 125 | \begin{itemize} |
| 126 | |
| 127 | \item Detailed changes are listed here. |
| 128 | |
| 129 | \end{itemize} |
| 130 | |
| 131 | |
| 132 | %====================================================================== |
| 133 | \subsection{Port-Specific Changes} |
| 134 | |
| 135 | Platform-specific changes go here. |
| 136 | |
| 137 | |
| 138 | %====================================================================== |
| 139 | \section{Other Changes and Fixes \label{section-other}} |
| 140 | |
| 141 | As usual, there were a bunch of other improvements and bugfixes |
| 142 | scattered throughout the source tree. A search through the CVS change |
| 143 | logs finds there were XXX patches applied and YYY bugs fixed between |
| 144 | Python 2.3 and 2.4. Both figures are likely to be underestimates. |
| 145 | |
| 146 | Some of the more notable changes are: |
| 147 | |
| 148 | \begin{itemize} |
| 149 | |
| 150 | \item Details go here. |
| 151 | |
| 152 | \end{itemize} |
| 153 | |
| 154 | |
| 155 | %====================================================================== |
| 156 | \section{Porting to Python 2.4} |
| 157 | |
| 158 | This section lists previously described changes that may require |
| 159 | changes to your code: |
| 160 | |
| 161 | \begin{itemize} |
| 162 | |
Martin v. Löwis | c6bb6c0 | 2003-09-20 15:52:21 +0000 | [diff] [blame] | 163 | \item dircache.listdir now passes exceptions to the caller, |
| 164 | instead of returning empty lists. |
Fred Drake | ed0fa3d | 2003-07-30 19:14:09 +0000 | [diff] [blame] | 165 | |
| 166 | \end{itemize} |
| 167 | |
| 168 | |
| 169 | %====================================================================== |
| 170 | \section{Acknowledgements \label{acks}} |
| 171 | |
| 172 | The author would like to thank the following people for offering |
| 173 | suggestions, corrections and assistance with various drafts of this |
| 174 | article: . |
| 175 | |
| 176 | \end{document} |