Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 1 | \documentclass{howto} |
| 2 | \usepackage{distutils} |
| 3 | % $Id$ |
| 4 | |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 5 | |
| 6 | \title{What's New in Python 2.5} |
| 7 | \release{0.0} |
Andrew M. Kuchling | 92e2495 | 2004-12-03 13:54:09 +0000 | [diff] [blame] | 8 | \author{A.M. Kuchling} |
| 9 | \authoraddress{\email{amk@amk.ca}} |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 10 | |
| 11 | \begin{document} |
| 12 | \maketitle |
| 13 | \tableofcontents |
| 14 | |
| 15 | This article explains the new features in Python 2.5. No release date |
Andrew M. Kuchling | 92e2495 | 2004-12-03 13:54:09 +0000 | [diff] [blame] | 16 | for Python 2.5 has been set; it will probably be released in late 2005. |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 17 | |
| 18 | % Compare with previous release in 2 - 3 sentences here. |
| 19 | |
| 20 | This article doesn't attempt to provide a complete specification of |
| 21 | the new features, but instead provides a convenient overview. For |
| 22 | full details, you should refer to the documentation for Python 2.5. |
| 23 | % add hyperlink when the documentation becomes available online. |
| 24 | If you want to understand the complete implementation and design |
| 25 | rationale, refer to the PEP for a particular new feature. |
| 26 | |
| 27 | |
| 28 | %====================================================================== |
Andrew M. Kuchling | 3e41b05 | 2005-03-01 00:53:46 +0000 | [diff] [blame] | 29 | \section{PEP 309: Partial Function Application} |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 30 | |
Andrew M. Kuchling | b1c96fd | 2005-03-20 21:42:04 +0000 | [diff] [blame] | 31 | The \module{functional} module is intended to contain tools for |
| 32 | functional-style programming. Currently it only contains |
| 33 | \class{partial}, but new functions will probably be added in future |
| 34 | versions of Python. |
| 35 | |
Andrew M. Kuchling | 4b000cd | 2005-04-09 15:51:44 +0000 | [diff] [blame] | 36 | For programs written in a functional style, it can be useful to |
| 37 | construct variants of existing functions that have some of the |
| 38 | parameters filled in. Consider a Python function \code{f(a, b, c)}; |
| 39 | you could create a new function \code{g(b, c)} that was equivalent to |
| 40 | \code{f(1, b, c)}. This is called ``partial function application'', |
| 41 | and is provided by the \class{partial} class in the new |
| 42 | \module{functional} module. |
| 43 | |
| 44 | The constructor for \class{partial} takes the arguments |
| 45 | \code{(\var{function}, \var{arg1}, \var{arg2}, ... |
| 46 | \var{kwarg1}=\var{value1}, \var{kwarg2}=\var{value2})}. The resulting |
| 47 | object is callable, so you can just call it to invoke \var{function} |
| 48 | with the filled-in arguments. |
| 49 | |
| 50 | Here's a small but realistic example: |
| 51 | |
| 52 | \begin{verbatim} |
| 53 | import functional |
| 54 | |
| 55 | def log (message, subsystem): |
| 56 | "Write the contents of 'message' to the specified subsystem." |
| 57 | print '%s: %s' % (subsystem, message) |
| 58 | ... |
| 59 | |
| 60 | server_log = functional.partial(log, subsystem='server') |
| 61 | \end{verbatim} |
| 62 | |
Andrew M. Kuchling | 6af7fe0 | 2005-08-02 17:20:36 +0000 | [diff] [blame] | 63 | Here's another example, from a program that uses PyGTk. Here a |
| 64 | context-sensitive pop-up menu is being constructed dynamically. The |
| 65 | callback provided for the menu option is a partially applied version |
| 66 | of the \method{open_item()} method, where the first argument has been |
| 67 | provided. |
Andrew M. Kuchling | 4b000cd | 2005-04-09 15:51:44 +0000 | [diff] [blame] | 68 | |
Andrew M. Kuchling | 6af7fe0 | 2005-08-02 17:20:36 +0000 | [diff] [blame] | 69 | \begin{verbatim} |
| 70 | ... |
| 71 | class Application: |
| 72 | def open_item(self, path): |
| 73 | ... |
| 74 | def init (self): |
| 75 | open_func = functional.partial(self.open_item, item_path) |
| 76 | popup_menu.append( ("Open", open_func, 1) ) |
| 77 | \end{verbatim} |
Andrew M. Kuchling | b1c96fd | 2005-03-20 21:42:04 +0000 | [diff] [blame] | 78 | |
| 79 | |
| 80 | \begin{seealso} |
| 81 | |
| 82 | \seepep{309}{Partial Function Application}{PEP proposed and written by |
| 83 | Peter Harris; implemented by Hye-Shik Chang, with adaptations by |
| 84 | Raymond Hettinger.} |
| 85 | |
| 86 | \end{seealso} |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 87 | |
| 88 | |
| 89 | %====================================================================== |
Fred Drake | db7b002 | 2005-03-20 22:19:47 +0000 | [diff] [blame] | 90 | \section{PEP 314: Metadata for Python Software Packages v1.1} |
| 91 | |
Andrew M. Kuchling | d8d732e | 2005-04-09 23:59:41 +0000 | [diff] [blame] | 92 | Some simple dependency support was added to Distutils. The |
| 93 | \function{setup()} function now has \code{requires},\code{provides}, |
| 94 | and \code{obsoletes}. When you build a source distribution using the |
| 95 | \code{sdist} command, the dependency information will be recorded in |
| 96 | the \file{PKG-INFO} file. |
| 97 | |
| 98 | Another new keyword is \code{download_url}, which should be set to a |
| 99 | URL for the package's source code. This means it's now possible to |
| 100 | look up an entry in the package index, determine the dependencies for |
| 101 | a package, and download the required packages. |
| 102 | |
| 103 | % XXX put example here |
| 104 | |
| 105 | \begin{seealso} |
| 106 | |
| 107 | \seepep{314}{Metadata for Python Software Packages v1.1}{PEP proposed |
| 108 | and written by A.M. Kuchling, Richard Jones, and Fred Drake; |
| 109 | implemented by Richard Jones and Fred Drake.} |
| 110 | |
| 111 | \end{seealso} |
Fred Drake | db7b002 | 2005-03-20 22:19:47 +0000 | [diff] [blame] | 112 | |
| 113 | |
| 114 | %====================================================================== |
Andrew M. Kuchling | a2e21cb | 2005-08-02 17:13:21 +0000 | [diff] [blame] | 115 | \section{PEP 342: New Generator Features} |
| 116 | |
Andrew M. Kuchling | 150e349 | 2005-08-23 00:56:06 +0000 | [diff] [blame] | 117 | As introduced in Python 2.3, generators only produce output; once a |
| 118 | generator's code was invoked to create an iterator, there's no way to |
| 119 | pass new parameters into the function when its execution is resumed. |
Andrew M. Kuchling | 0738206 | 2005-08-27 18:45:47 +0000 | [diff] [blame] | 120 | Hackish solutions to this include making the generator's code look at |
| 121 | a global variable and then changing the global variable's value, or |
| 122 | passing in some mutable object that callers then modify. Python |
| 123 | 2.5 adds the ability to pass values \emph{into} a generator. |
Andrew M. Kuchling | 150e349 | 2005-08-23 00:56:06 +0000 | [diff] [blame] | 124 | |
| 125 | To refresh your memory of basic generators, here's a simple example: |
| 126 | |
| 127 | \begin{verbatim} |
| 128 | def counter (maximum): |
| 129 | i = 0 |
| 130 | while i < maximum: |
| 131 | yield i |
| 132 | i += 1 |
| 133 | \end{verbatim} |
| 134 | |
Andrew M. Kuchling | 0738206 | 2005-08-27 18:45:47 +0000 | [diff] [blame] | 135 | When you call \code{counter(10)}, the result is an iterator that |
| 136 | returns the values from 0 up to 9. On encountering the |
| 137 | \keyword{yield} statement, the iterator returns the provided value and |
| 138 | suspends the function's execution, preserving the local variables. |
| 139 | Execution resumes on the following call to the iterator's |
| 140 | \method{next()} method, picking up after the \keyword{yield}. |
Andrew M. Kuchling | 150e349 | 2005-08-23 00:56:06 +0000 | [diff] [blame] | 141 | |
Andrew M. Kuchling | 0738206 | 2005-08-27 18:45:47 +0000 | [diff] [blame] | 142 | In Python 2.3, \keyword{yield} was a statement; it didn't return any |
| 143 | value. In 2.5, \keyword{yield} is now an expression, returning a |
| 144 | value that can be assigned to a variable or otherwise operated on: |
Andrew M. Kuchling | a2e21cb | 2005-08-02 17:13:21 +0000 | [diff] [blame] | 145 | |
Andrew M. Kuchling | 0738206 | 2005-08-27 18:45:47 +0000 | [diff] [blame] | 146 | \begin{verbatim} |
| 147 | val = (yield i) |
| 148 | \end{verbatim} |
| 149 | |
| 150 | I recommend that you always put parentheses around a \keyword{yield} |
| 151 | expression when you're doing something with the returned value, as in |
| 152 | the above example. The parentheses aren't always necessary, but it's |
| 153 | easier to always add them instead of having to remember when they're |
| 154 | needed. The exact rules are that a \keyword{yield}-expression must |
| 155 | always be parenthesized except when it occurs at the top-level |
| 156 | expression on the right-hand side of an assignment, meaning |
| 157 | you can to write \code{val = yield i} but \code{val = (yield i) + 12}. |
| 158 | |
| 159 | Values are sent into a generator by calling its |
| 160 | \method{send(\var{value})} method. The generator's code is then |
| 161 | resumed and the \keyword{yield} expression produces \var{value}. |
| 162 | If the regular \method{next()} method is called, the \keyword{yield} |
| 163 | returns \constant{None}. |
| 164 | |
| 165 | Here's the previous example, modified to allow changing the value of |
| 166 | the internal counter. |
| 167 | |
| 168 | \begin{verbatim} |
| 169 | def counter (maximum): |
| 170 | i = 0 |
| 171 | while i < maximum: |
| 172 | val = (yield i) |
| 173 | # If value provided, change counter |
| 174 | if val is not None: |
| 175 | i = val |
| 176 | else: |
| 177 | i += 1 |
| 178 | \end{verbatim} |
| 179 | |
| 180 | And here's an example of changing the counter: |
| 181 | |
| 182 | \begin{verbatim} |
| 183 | >>> it = counter(10) |
| 184 | >>> print it.next() |
| 185 | 0 |
| 186 | >>> print it.next() |
| 187 | 1 |
| 188 | >>> print it.send(8) |
| 189 | 8 |
| 190 | >>> print it.next() |
| 191 | 9 |
| 192 | >>> print it.next() |
| 193 | Traceback (most recent call last): |
| 194 | File ``t.py'', line 15, in ? |
| 195 | print it.next() |
| 196 | StopIteration |
Andrew M. Kuchling | c203370 | 2005-08-29 13:30:12 +0000 | [diff] [blame^] | 197 | \end{verbatim} |
Andrew M. Kuchling | 0738206 | 2005-08-27 18:45:47 +0000 | [diff] [blame] | 198 | |
| 199 | Because \keyword{yield} will often be returning \constant{None}, |
| 200 | you shouldn't just use its value in expressions unless you're sure |
| 201 | that only the \method{send()} method will be used. |
| 202 | |
| 203 | There are two other new methods on generators in addition to |
| 204 | \method{send()}: |
| 205 | |
| 206 | \begin{itemize} |
| 207 | |
| 208 | \item \method{throw(\var{type}, \var{value}=None, |
| 209 | \var{traceback}=None)} is used to raise an exception inside the |
| 210 | generator; the exception is raised by the \keyword{yield} expression |
| 211 | where the generator's execution is paused. |
| 212 | |
| 213 | \item \method{close()} raises a new \exception{GeneratorExit} |
| 214 | exception inside the generator to terminate the iteration. |
| 215 | On receiving this |
| 216 | exception, the generator's code must either raise |
| 217 | \exception{GeneratorExit} or \exception{StopIteration}; catching the |
| 218 | exception and doing anything else is illegal and will trigger |
| 219 | a \exception{RuntimeError}. \method{close()} will also be called by |
| 220 | Python's garbage collection when the generator is garbage-collected. |
| 221 | |
| 222 | If you need to run cleanup code in case of a \exception{GeneratorExit}, |
| 223 | I suggest using a \code{try: ... finally:} suite instead of |
| 224 | catching \exception{GeneratorExit}. |
| 225 | |
| 226 | \end{itemize} |
| 227 | |
| 228 | The cumulative effect of these changes is to turn generators from |
| 229 | one-way producers of information into both producers and consumers. |
| 230 | Generators also become \emph{coroutines}, a more generalized form of |
| 231 | subroutines; subroutines are entered at one point and exited at |
| 232 | another point (the top of the function, and a \keyword{return |
| 233 | statement}), but coroutines can be entered, exited, and resumed at |
| 234 | many different points (the \keyword{yield} statements).science term |
| 235 | |
| 236 | |
Andrew M. Kuchling | a2e21cb | 2005-08-02 17:13:21 +0000 | [diff] [blame] | 237 | \begin{seealso} |
| 238 | |
| 239 | \seepep{342}{Coroutines via Enhanced Generators}{PEP written by |
| 240 | Guido van Rossum and Phillip J. Eby; |
Andrew M. Kuchling | 0738206 | 2005-08-27 18:45:47 +0000 | [diff] [blame] | 241 | implemented by Phillip J. Eby. Includes examples of |
| 242 | some fancier uses of generators as coroutines.} |
| 243 | |
| 244 | \seeurl{http://en.wikipedia.org/wiki/Coroutine}{The Wikipedia entry for |
| 245 | coroutines.} |
| 246 | |
| 247 | \seeurl{http://www.sidhe.org/~dan/blog/archives/000178.html}{An |
| 248 | explanation of coroutines from a Perl point of view, written by Dan |
| 249 | Sugalski.} |
Andrew M. Kuchling | a2e21cb | 2005-08-02 17:13:21 +0000 | [diff] [blame] | 250 | |
| 251 | \end{seealso} |
| 252 | |
| 253 | |
| 254 | %====================================================================== |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 255 | \section{Other Language Changes} |
| 256 | |
| 257 | Here are all of the changes that Python 2.5 makes to the core Python |
| 258 | language. |
| 259 | |
| 260 | \begin{itemize} |
Andrew M. Kuchling | 1cae3f5 | 2004-12-03 14:57:21 +0000 | [diff] [blame] | 261 | |
| 262 | \item The \function{min()} and \function{max()} built-in functions |
| 263 | gained a \code{key} keyword argument analogous to the \code{key} |
Andrew M. Kuchling | e9b1bf4 | 2005-03-20 19:26:30 +0000 | [diff] [blame] | 264 | argument for \method{sort()}. This argument supplies a function |
Andrew M. Kuchling | 1cae3f5 | 2004-12-03 14:57:21 +0000 | [diff] [blame] | 265 | that takes a single argument and is called for every value in the list; |
| 266 | \function{min()}/\function{max()} will return the element with the |
| 267 | smallest/largest return value from this function. |
| 268 | For example, to find the longest string in a list, you can do: |
| 269 | |
| 270 | \begin{verbatim} |
| 271 | L = ['medium', 'longest', 'short'] |
| 272 | # Prints 'longest' |
| 273 | print max(L, key=len) |
| 274 | # Prints 'short', because lexicographically 'short' has the largest value |
| 275 | print max(L) |
| 276 | \end{verbatim} |
| 277 | |
| 278 | (Contributed by Steven Bethard and Raymond Hettinger.) |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 279 | |
Andrew M. Kuchling | 150e349 | 2005-08-23 00:56:06 +0000 | [diff] [blame] | 280 | \item Two new built-in functions, \function{any()} and |
| 281 | \function{all()}, evaluate whether an iterator contains any true or |
| 282 | false values. \function{any()} returns \constant{True} if any value |
| 283 | returned by the iterator is true; otherwise it will return |
| 284 | \constant{False}. \function{all()} returns \constant{True} only if |
| 285 | all of the values returned by the iterator evaluate as being true. |
| 286 | |
| 287 | % XXX who added? |
| 288 | |
| 289 | |
Andrew M. Kuchling | e9b1bf4 | 2005-03-20 19:26:30 +0000 | [diff] [blame] | 290 | \item The list of base classes in a class definition can now be empty. |
| 291 | As an example, this is now legal: |
| 292 | |
| 293 | \begin{verbatim} |
| 294 | class C(): |
| 295 | pass |
| 296 | \end{verbatim} |
| 297 | (Implemented by Brett Cannon.) |
| 298 | |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 299 | \end{itemize} |
| 300 | |
| 301 | |
| 302 | %====================================================================== |
| 303 | \subsection{Optimizations} |
| 304 | |
| 305 | \begin{itemize} |
| 306 | |
Andrew M. Kuchling | 150e349 | 2005-08-23 00:56:06 +0000 | [diff] [blame] | 307 | \item When they were introduced |
| 308 | in Python 2.4, the built-in \class{set} and \class{frozenset} types |
| 309 | were built on top of Python's dictionary type. |
| 310 | In 2.5 the internal data structure has been customized for implementing sets, |
| 311 | and as a result sets will use a third less memory and are somewhat faster. |
| 312 | (Implemented by Raymond Hettinger.) |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 313 | |
| 314 | \end{itemize} |
| 315 | |
| 316 | The net result of the 2.5 optimizations is that Python 2.5 runs the |
Andrew M. Kuchling | 92e2495 | 2004-12-03 13:54:09 +0000 | [diff] [blame] | 317 | pystone benchmark around XX\% faster than Python 2.4. |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 318 | |
| 319 | |
| 320 | %====================================================================== |
| 321 | \section{New, Improved, and Deprecated Modules} |
| 322 | |
| 323 | As usual, Python's standard library received a number of enhancements and |
| 324 | bug fixes. Here's a partial list of the most notable changes, sorted |
| 325 | alphabetically by module name. Consult the |
| 326 | \file{Misc/NEWS} file in the source tree for a more |
| 327 | complete list of changes, or look through the CVS logs for all the |
| 328 | details. |
| 329 | |
| 330 | \begin{itemize} |
| 331 | |
Andrew M. Kuchling | 150e349 | 2005-08-23 00:56:06 +0000 | [diff] [blame] | 332 | % collections.deque now has .remove() |
| 333 | |
Andrew M. Kuchling | 3e41b05 | 2005-03-01 00:53:46 +0000 | [diff] [blame] | 334 | % the cPickle module no longer accepts the deprecated None option in the |
| 335 | % args tuple returned by __reduce__(). |
| 336 | |
| 337 | % csv module improvements |
| 338 | |
| 339 | % datetime.datetime() now has a strptime class method which can be used to |
| 340 | % create datetime object using a string and format. |
| 341 | |
Andrew M. Kuchling | 150e349 | 2005-08-23 00:56:06 +0000 | [diff] [blame] | 342 | \item A new \module{hashlib} module has been added to replace the |
| 343 | \module{md5} and \module{sha} modules. \module{hashlib} adds support |
| 344 | for additional secure hashes (SHA-224, SHA-256, SHA-384, and SHA-512). |
| 345 | When available, the module uses OpenSSL for fast platform optimized |
| 346 | implementations of algorithms. The old \module{md5} and \module{sha} |
| 347 | modules still exist as wrappers around hashlib to preserve backwards |
| 348 | compatibility. (Contributed by Gregory P. Smith.) |
| 349 | |
Andrew M. Kuchling | e9b1bf4 | 2005-03-20 19:26:30 +0000 | [diff] [blame] | 350 | \item The \function{nsmallest()} and |
| 351 | \function{nlargest()} functions in the \module{heapq} module |
| 352 | now support a \code{key} keyword argument similar to the one |
| 353 | provided by the \function{min()}/\function{max()} functions |
| 354 | and the \method{sort()} methods. For example: |
| 355 | Example: |
| 356 | |
| 357 | \begin{verbatim} |
| 358 | >>> import heapq |
| 359 | >>> L = ["short", 'medium', 'longest', 'longer still'] |
| 360 | >>> heapq.nsmallest(2, L) # Return two lowest elements, lexicographically |
| 361 | ['longer still', 'longest'] |
| 362 | >>> heapq.nsmallest(2, L, key=len) # Return two shortest elements |
| 363 | ['short', 'medium'] |
| 364 | \end{verbatim} |
| 365 | |
| 366 | (Contributed by Raymond Hettinger.) |
| 367 | |
Andrew M. Kuchling | 511a3a8 | 2005-03-20 19:52:18 +0000 | [diff] [blame] | 368 | \item The \function{itertools.islice()} function now accepts |
| 369 | \code{None} for the start and step arguments. This makes it more |
| 370 | compatible with the attributes of slice objects, so that you can now write |
| 371 | the following: |
| 372 | |
| 373 | \begin{verbatim} |
| 374 | s = slice(5) # Create slice object |
| 375 | itertools.islice(iterable, s.start, s.stop, s.step) |
| 376 | \end{verbatim} |
| 377 | |
| 378 | (Contributed by Raymond Hettinger.) |
Andrew M. Kuchling | 3e41b05 | 2005-03-01 00:53:46 +0000 | [diff] [blame] | 379 | |
Andrew M. Kuchling | 150e349 | 2005-08-23 00:56:06 +0000 | [diff] [blame] | 380 | \item The \module{operator} module's \function{itemgetter()} |
| 381 | and \function{attrgetter()} functions now support multiple fields. |
| 382 | A call such as \code{operator.attrgetter('a', 'b')} |
| 383 | will return a function |
| 384 | that retrieves the \member{a} and \member{b} attributes. Combining |
| 385 | this new feature with the \method{sort()} method's \code{key} parameter |
| 386 | lets you easily sort lists using multiple fields. |
| 387 | |
| 388 | % XXX who added? |
| 389 | |
Andrew M. Kuchling | 3e41b05 | 2005-03-01 00:53:46 +0000 | [diff] [blame] | 390 | |
Andrew M. Kuchling | e9b1bf4 | 2005-03-20 19:26:30 +0000 | [diff] [blame] | 391 | \item The \module{os} module underwent a number of changes. The |
| 392 | \member{stat_float_times} variable now defaults to true, meaning that |
| 393 | \function{os.stat()} will now return time values as floats. (This |
| 394 | doesn't necessarily mean that \function{os.stat()} will return times |
| 395 | that are precise to fractions of a second; not all systems support |
| 396 | such precision.) |
Andrew M. Kuchling | 3e41b05 | 2005-03-01 00:53:46 +0000 | [diff] [blame] | 397 | |
Andrew M. Kuchling | 150e349 | 2005-08-23 00:56:06 +0000 | [diff] [blame] | 398 | Constants named \member{os.SEEK_SET}, \member{os.SEEK_CUR}, and |
Andrew M. Kuchling | e9b1bf4 | 2005-03-20 19:26:30 +0000 | [diff] [blame] | 399 | \member{os.SEEK_END} have been added; these are the parameters to the |
Andrew M. Kuchling | 150e349 | 2005-08-23 00:56:06 +0000 | [diff] [blame] | 400 | \function{os.lseek()} function. Two new constants for locking are |
| 401 | \member{os.O_SHLOCK} and \member{os.O_EXLOCK}. |
| 402 | |
| 403 | On FreeBSD, the \function{os.stat()} function now returns |
| 404 | times with nanosecond resolution, and the returned object |
| 405 | now has \member{st_gen} and \member{st_birthtime}. |
| 406 | The \member{st_flags} member is also available, if the platform supports it. |
| 407 | % XXX patch 1180695, 1212117 |
| 408 | |
| 409 | \item New module: \module{spwd} provides functions for accessing the |
| 410 | shadow password database on systems that support it. |
| 411 | % XXX give example |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 412 | |
Andrew M. Kuchling | e9b1bf4 | 2005-03-20 19:26:30 +0000 | [diff] [blame] | 413 | \item The \class{TarFile} class in the \module{tarfile} module now has |
Georg Brandl | 08c02db | 2005-07-22 18:39:19 +0000 | [diff] [blame] | 414 | an \method{extractall()} method that extracts all members from the |
Andrew M. Kuchling | e9b1bf4 | 2005-03-20 19:26:30 +0000 | [diff] [blame] | 415 | archive into the current working directory. It's also possible to set |
| 416 | a different directory as the extraction target, and to unpack only a |
Andrew M. Kuchling | 150e349 | 2005-08-23 00:56:06 +0000 | [diff] [blame] | 417 | subset of the archive's members. |
Andrew M. Kuchling | e9b1bf4 | 2005-03-20 19:26:30 +0000 | [diff] [blame] | 418 | |
Andrew M. Kuchling | 150e349 | 2005-08-23 00:56:06 +0000 | [diff] [blame] | 419 | A tarfile's compression can be autodetected by |
| 420 | using the mode \code{'r|*'}. |
| 421 | % patch 918101 |
| 422 | (Contributed by Lars Gust\"abel.) |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 423 | |
Andrew M. Kuchling | 150e349 | 2005-08-23 00:56:06 +0000 | [diff] [blame] | 424 | \item The \module{xmlrpclib} module now supports returning |
| 425 | \class{datetime} objects for the XML-RPC date type. Supply |
| 426 | \code{use_datetime=True} to the \function{loads()} function |
| 427 | or the \class{Unmarshaller} class to enable this feature. |
| 428 | % XXX patch 1120353 |
| 429 | |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 430 | |
Fred Drake | 114b8ca | 2005-03-21 05:47:11 +0000 | [diff] [blame] | 431 | \end{itemize} |
Andrew M. Kuchling | e9b1bf4 | 2005-03-20 19:26:30 +0000 | [diff] [blame] | 432 | |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 433 | |
| 434 | |
| 435 | %====================================================================== |
| 436 | % whole new modules get described in \subsections here |
| 437 | |
Andrew M. Kuchling | 150e349 | 2005-08-23 00:56:06 +0000 | [diff] [blame] | 438 | % XXX new distutils features: upload |
| 439 | |
| 440 | |
| 441 | |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 442 | |
| 443 | % ====================================================================== |
| 444 | \section{Build and C API Changes} |
| 445 | |
| 446 | Changes to Python's build process and to the C API include: |
| 447 | |
| 448 | \begin{itemize} |
| 449 | |
Andrew M. Kuchling | 150e349 | 2005-08-23 00:56:06 +0000 | [diff] [blame] | 450 | \item The built-in set types now have an official C API. Call |
| 451 | \cfunction{PySet_New()} and \cfunction{PyFrozenSet_New()} to create a |
| 452 | new set, \cfunction{PySet_Add()} and \cfunction{PySet_Discard()} to |
| 453 | add and remove elements, and \cfunction{PySet_Contains} and |
| 454 | \cfunction{PySet_Size} to examine the set's state. |
| 455 | |
| 456 | \item The \cfunction{PyRange_New()} function was removed. It was |
| 457 | never documented, never used in the core code, and had dangerously lax |
| 458 | error checking. |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 459 | |
| 460 | \end{itemize} |
| 461 | |
| 462 | |
| 463 | %====================================================================== |
| 464 | \subsection{Port-Specific Changes} |
| 465 | |
| 466 | Platform-specific changes go here. |
| 467 | |
| 468 | |
| 469 | %====================================================================== |
| 470 | \section{Other Changes and Fixes \label{section-other}} |
| 471 | |
| 472 | As usual, there were a bunch of other improvements and bugfixes |
| 473 | scattered throughout the source tree. A search through the CVS change |
| 474 | logs finds there were XXX patches applied and YYY bugs fixed between |
Andrew M. Kuchling | 92e2495 | 2004-12-03 13:54:09 +0000 | [diff] [blame] | 475 | Python 2.4 and 2.5. Both figures are likely to be underestimates. |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 476 | |
| 477 | Some of the more notable changes are: |
| 478 | |
| 479 | \begin{itemize} |
| 480 | |
| 481 | \item Details go here. |
| 482 | |
| 483 | \end{itemize} |
| 484 | |
| 485 | |
| 486 | %====================================================================== |
| 487 | \section{Porting to Python 2.5} |
| 488 | |
| 489 | This section lists previously described changes that may require |
| 490 | changes to your code: |
| 491 | |
| 492 | \begin{itemize} |
| 493 | |
Andrew M. Kuchling | 3e41b05 | 2005-03-01 00:53:46 +0000 | [diff] [blame] | 494 | \item Some old deprecated modules (\module{statcache}, \module{tzparse}, |
| 495 | \module{whrandom}) have been moved to \file{Lib/lib-old}. |
Andrew M. Kuchling | 0c35db9 | 2005-03-20 20:06:49 +0000 | [diff] [blame] | 496 | You can get access to these modules again by adding the directory |
| 497 | to your \code{sys.path}: |
| 498 | |
| 499 | \begin{verbatim} |
| 500 | import os |
| 501 | from distutils import sysconfig |
| 502 | |
| 503 | lib_dir = sysconfig.get_python_lib(standard_lib=True) |
| 504 | old_dir = os.path.join(lib_dir, 'lib-old') |
| 505 | sys.path.append(old_dir) |
| 506 | \end{verbatim} |
| 507 | |
| 508 | Doing so is discouraged, however; it's better to update any code that |
| 509 | still uses these modules. |
Andrew M. Kuchling | 3e41b05 | 2005-03-01 00:53:46 +0000 | [diff] [blame] | 510 | |
| 511 | % the pickle module no longer uses the deprecated bin parameter. |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 512 | |
| 513 | \end{itemize} |
| 514 | |
| 515 | |
| 516 | %====================================================================== |
| 517 | \section{Acknowledgements \label{acks}} |
| 518 | |
| 519 | The author would like to thank the following people for offering |
| 520 | suggestions, corrections and assistance with various drafts of this |
| 521 | article: . |
| 522 | |
| 523 | \end{document} |