Andrew M. Kuchling | a8defaa | 2001-05-05 16:37:29 +0000 | [diff] [blame] | 1 | \documentclass{howto} |
| 2 | |
| 3 | % $Id$ |
| 4 | |
| 5 | \title{What's New in Python 2.2} |
| 6 | \release{0.01} |
| 7 | \author{A.M. Kuchling} |
Andrew M. Kuchling | 7bf8277 | 2001-07-11 18:54:26 +0000 | [diff] [blame] | 8 | \authoraddress{\email{akuchlin@mems-exchange.org}} |
Andrew M. Kuchling | a8defaa | 2001-05-05 16:37:29 +0000 | [diff] [blame] | 9 | \begin{document} |
| 10 | \maketitle\tableofcontents |
| 11 | |
| 12 | \section{Introduction} |
| 13 | |
| 14 | {\large This document is a draft, and is subject to change until the |
| 15 | final version of Python 2.2 is released. Currently it's not up to |
| 16 | date at all. Please send any comments, bug reports, or questions, no |
Andrew M. Kuchling | 7bf8277 | 2001-07-11 18:54:26 +0000 | [diff] [blame] | 17 | matter how minor, to \email{akuchlin@mems-exchange.org}. } |
Andrew M. Kuchling | a8defaa | 2001-05-05 16:37:29 +0000 | [diff] [blame] | 18 | |
Andrew M. Kuchling | 7bf8277 | 2001-07-11 18:54:26 +0000 | [diff] [blame] | 19 | This article explains the new features in Python 2.2. Python 2.2 |
| 20 | includes some significant changes that go far toward cleaning up the |
| 21 | language's darkest corners, and some exciting new features. |
Andrew M. Kuchling | a8defaa | 2001-05-05 16:37:29 +0000 | [diff] [blame] | 22 | |
| 23 | This article doesn't attempt to provide a complete specification for |
| 24 | the new features, but instead provides a convenient overview of the |
| 25 | new features. For full details, you should refer to 2.2 documentation |
| 26 | such as the Library Reference and the Reference Guide, or to the PEP |
| 27 | for a particular new feature. |
| 28 | |
| 29 | The final release of Python 2.2 is planned for October 2001. |
| 30 | |
| 31 | %====================================================================== |
Andrew M. Kuchling | 4dbf871 | 2001-07-16 02:17:14 +0000 | [diff] [blame^] | 32 | % It looks like this set of changes will likely get into 2.2, |
| 33 | % so I need to read and digest the relevant PEPs. |
Andrew M. Kuchling | 7bf8277 | 2001-07-11 18:54:26 +0000 | [diff] [blame] | 34 | %\section{PEP 252: Type and Class Changes} |
Andrew M. Kuchling | a8defaa | 2001-05-05 16:37:29 +0000 | [diff] [blame] | 35 | |
Andrew M. Kuchling | 7bf8277 | 2001-07-11 18:54:26 +0000 | [diff] [blame] | 36 | %XXX |
Andrew M. Kuchling | a8defaa | 2001-05-05 16:37:29 +0000 | [diff] [blame] | 37 | |
Andrew M. Kuchling | 7bf8277 | 2001-07-11 18:54:26 +0000 | [diff] [blame] | 38 | %\begin{seealso} |
Andrew M. Kuchling | a8defaa | 2001-05-05 16:37:29 +0000 | [diff] [blame] | 39 | |
Andrew M. Kuchling | 7bf8277 | 2001-07-11 18:54:26 +0000 | [diff] [blame] | 40 | %\seepep{252}{Making Types Look More Like Classes}{Written and implemented |
| 41 | %by GvR.} |
Andrew M. Kuchling | a8defaa | 2001-05-05 16:37:29 +0000 | [diff] [blame] | 42 | |
Andrew M. Kuchling | 7bf8277 | 2001-07-11 18:54:26 +0000 | [diff] [blame] | 43 | %\end{seealso} |
Andrew M. Kuchling | a8defaa | 2001-05-05 16:37:29 +0000 | [diff] [blame] | 44 | |
| 45 | %====================================================================== |
Andrew M. Kuchling | 4dbf871 | 2001-07-16 02:17:14 +0000 | [diff] [blame^] | 46 | \section{PEP 234: Iterators} |
| 47 | |
| 48 | A significant addition to 2.2 is an iteration interface at both the C |
| 49 | and Python levels. Objects can define how they can be looped over by |
| 50 | callers. |
| 51 | |
| 52 | In Python versions up to 2.1, the usual way to make \code{for item in |
| 53 | obj} work is to define a \method{__getitem__()} method that looks |
| 54 | something like this: |
| 55 | |
| 56 | \begin{verbatim} |
| 57 | def __getitem__(self, index): |
| 58 | return <next item> |
| 59 | \end{verbatim} |
| 60 | |
| 61 | \method{__getitem__()} is more properly used to define an indexing |
| 62 | operation on an object so that you can write \code{obj[5]} to retrieve |
| 63 | the fifth element. It's a bit misleading when you're using this only |
| 64 | to support \keyword{for} loops. Consider some file-like object that |
| 65 | wants to be looped over; the \var{index} parameter is essentially |
| 66 | meaningless, as the class probably assumes that a series of |
| 67 | \method{__getitem__()} calls will be made, with \var{index} |
| 68 | incrementing by one each time. In other words, the presence of the |
| 69 | \method{__getitem__()} method doesn't mean that \code{file[5]} will |
| 70 | work, though it really should. |
| 71 | |
| 72 | In Python 2.2, iteration can be implemented separately, and |
| 73 | \method{__getitem__()} methods can be limited to classes that really |
| 74 | do support random access. The basic idea of iterators is quite |
| 75 | simple. A new built-in function, \function{iter(obj)}, returns an |
| 76 | iterator for the object \var{obj}. (It can also take two arguments: |
| 77 | \code{iter(\var{C}, \var{sentinel})} will call the callable \var{C}, until it |
| 78 | returns \var{sentinel}, which will signal that the iterator is done. This form probably won't be used very often.) |
| 79 | |
| 80 | Python classes can define an \method{__iter__()} method, which should |
| 81 | create and return a new iterator for the object; if the object is its |
| 82 | own iterator, this method can just return \code{self}. In particular, |
| 83 | iterators will usually be their own iterators. Extension types |
| 84 | implemented in C can implement a \code{tp_iter} function in order to |
| 85 | return an iterator, too. |
| 86 | |
| 87 | So what do iterators do? They have one required method, |
| 88 | \method{next()}, which takes no arguments and returns the next value. |
| 89 | When there are no more values to be returned, calling \method{next()} |
| 90 | should raise the \exception{StopIteration} exception. |
| 91 | |
| 92 | \begin{verbatim} |
| 93 | >>> L = [1,2,3] |
| 94 | >>> i = iter(L) |
| 95 | >>> print i |
| 96 | <iterator object at 0x8116870> |
| 97 | >>> i.next() |
| 98 | 1 |
| 99 | >>> i.next() |
| 100 | 2 |
| 101 | >>> i.next() |
| 102 | 3 |
| 103 | >>> i.next() |
| 104 | Traceback (most recent call last): |
| 105 | File "<stdin>", line 1, in ? |
| 106 | StopIteration |
| 107 | >>> |
| 108 | \end{verbatim} |
| 109 | |
| 110 | In 2.2, Python's \keyword{for} statement no longer expects a sequence; |
| 111 | it expects something for which \function{iter()} will return something. |
| 112 | For backward compatibility, and convenience, an iterator is |
| 113 | automatically constructed for sequences that don't implement |
| 114 | \method{__iter__()} or a \code{tp_iter} slot, so \code{for i in |
| 115 | [1,2,3]} will still work. Wherever the Python interpreter loops over |
| 116 | a sequence, it's been changed to use the iterator protocol. This |
| 117 | means you can do things like this: |
| 118 | |
| 119 | \begin{verbatim} |
| 120 | >>> i = iter(L) |
| 121 | >>> a,b,c = i |
| 122 | >>> a,b,c |
| 123 | (1, 2, 3) |
| 124 | >>> |
| 125 | \end{verbatim} |
| 126 | |
| 127 | Iterator support has been added to some of Python's basic types. The |
| 128 | \keyword{in} operator now works on dictionaries, so \code{\var{key} in |
| 129 | dict} is now equivalent to \code{dict.has_key(\var{key})}. |
| 130 | Calling \function{iter()} on a dictionary will return an iterator which loops over their keys: |
| 131 | |
| 132 | \begin{verbatim} |
| 133 | >>> m = {'Jan': 1, 'Feb': 2, 'Mar': 3, 'Apr': 4, 'May': 5, 'Jun': 6, |
| 134 | ... 'Jul': 7, 'Aug': 8, 'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12} |
| 135 | >>> for key in m: print key, m[key] |
| 136 | ... |
| 137 | Mar 3 |
| 138 | Feb 2 |
| 139 | Aug 8 |
| 140 | Sep 9 |
| 141 | May 5 |
| 142 | Jun 6 |
| 143 | Jul 7 |
| 144 | Jan 1 |
| 145 | Apr 4 |
| 146 | Nov 11 |
| 147 | Dec 12 |
| 148 | Oct 10 |
| 149 | >>> |
| 150 | \end{verbatim} |
| 151 | |
| 152 | That's just the default behaviour. If you want to iterate over keys, |
| 153 | values, or key/value pairs, you can explicitly call the |
| 154 | \method{iterkeys()}, \method{itervalues()}, or \method{iteritems()} |
| 155 | methods to get an appropriate iterator. |
| 156 | |
| 157 | Files also provide an iterator, which calls its \method{readline()} |
| 158 | method until there are no more lines in the file. This means you can |
| 159 | now read each line of a file using code like this: |
| 160 | |
| 161 | \begin{verbatim} |
| 162 | for line in file: |
| 163 | # do something for each line |
| 164 | \end{verbatim} |
| 165 | |
| 166 | Note that you can only go forward in an iterator; there's no way to |
| 167 | get the previous element, reset the iterator, or make a copy of it. |
| 168 | An iterator object could provide such additional capabilities, but the iterator protocol only requires a \method{next()} method. |
| 169 | |
| 170 | \begin{seealso} |
| 171 | |
| 172 | \seepep{234}{Iterators}{Written by Ka-Ping Yee and GvR; implemented |
| 173 | by the Python Labs crew, mostly by GvR and Tim Peters.} |
| 174 | |
| 175 | \end{seealso} |
| 176 | |
| 177 | %====================================================================== |
| 178 | \section{PEP 255: Simple Generators} |
| 179 | |
| 180 | Generators are another new feature, one that interacts with the |
| 181 | introduction of iterators. |
| 182 | |
| 183 | You're doubtless familiar with how function calls work in Python or |
| 184 | C. When you call a function, it gets a private area where its local |
| 185 | variables are created. When the function reaches a \keyword{return} |
| 186 | statement, the local variables are destroyed and the resulting value |
| 187 | is returned to the caller. A later call to the same function will get |
| 188 | a fresh new set of local variables. But, what if the local variables |
| 189 | weren't destroyed on exiting a function? What if you could later |
| 190 | resume the function where it left off? This is what generators |
| 191 | provide; they can be thought of as resumable functions. |
| 192 | |
| 193 | Here's the simplest example of a generator function: |
| 194 | |
| 195 | \begin{verbatim} |
| 196 | def generate_ints(N): |
| 197 | for i in range(N): |
| 198 | yield i |
| 199 | \end{verbatim} |
| 200 | |
| 201 | A new keyword, \keyword{yield}, was introduced for generators. Any |
| 202 | function containing a \keyword{yield} statement is a generator |
| 203 | function; this is detected by Python's bytecode compiler which |
| 204 | compiles the function specially. When you call a generator function, |
| 205 | it doesn't return a single value; instead it returns a generator |
| 206 | object that supports the iterator interface. On executing the |
| 207 | \keyword{yield} statement, the generator outputs the value of |
| 208 | \code{i}, similar to a \keyword{return} statement. The big difference |
| 209 | between \keyword{yield} and a \keyword{return} statement is that, on |
| 210 | reaching a \keyword{yield} the generator's state of execution is |
| 211 | suspended and local variables are preserved. On the next call to the |
| 212 | generator's \code{.next()} method, the function will resume executing |
| 213 | immediately after the \keyword{yield} statement. (For complicated |
| 214 | reasons, the \keyword{yield} statement isn't allowed inside the |
| 215 | \keyword{try} block of a \code{try...finally} statement; read PEP 255 |
| 216 | for a full explanation of the interaction between \keyword{yield} and |
| 217 | exceptions.) |
| 218 | |
| 219 | Here's a sample usage of the \function{generate_ints} generator: |
| 220 | |
| 221 | \begin{verbatim} |
| 222 | >>> gen = generate_ints(3) |
| 223 | >>> gen |
| 224 | <generator object at 0x8117f90> |
| 225 | >>> gen.next() |
| 226 | 0 |
| 227 | >>> gen.next() |
| 228 | 1 |
| 229 | >>> gen.next() |
| 230 | 2 |
| 231 | >>> gen.next() |
| 232 | Traceback (most recent call last): |
| 233 | File "<stdin>", line 1, in ? |
| 234 | File "<stdin>", line 2, in generate_ints |
| 235 | StopIteration |
| 236 | >>> |
| 237 | \end{verbatim} |
| 238 | |
| 239 | You could equally write \code{for i in generate_ints(5)}, or |
| 240 | \code{a,b,c = generate_ints(3)}. |
| 241 | |
| 242 | Inside a generator function, the \keyword{return} statement can only |
| 243 | be used without a value, and is equivalent to raising the |
| 244 | \exception{StopIteration} exception; afterwards the generator cannot |
| 245 | return any further values. \keyword{return} with a value, such as |
| 246 | \code{return 5}, is a syntax error inside a generator function. You |
| 247 | can also raise \exception{StopIteration} manually, or just let the |
| 248 | thread of execution fall off the bottom of the function, to achieve |
| 249 | the same effect. |
| 250 | |
| 251 | You could achieve the effect of generators manually by writing your |
| 252 | own class, and storing all the local variables of the generator as |
| 253 | instance variables. For example, returning a list of integers could |
| 254 | be done by setting \code{self.count} to 0, and having the |
| 255 | \method{next()} method increment \code{self.count} and return it. |
| 256 | because it would be easy to write a Python class. However, for a |
| 257 | moderately complicated generator, writing a corresponding class would |
| 258 | be much messier. \file{Lib/test/test_generators.py} contains a number |
| 259 | of more interesting examples. The simplest one implements an in-order |
| 260 | traversal of a tree using generators recursively. |
| 261 | |
| 262 | \begin{verbatim} |
| 263 | # A recursive generator that generates Tree leaves in in-order. |
| 264 | def inorder(t): |
| 265 | if t: |
| 266 | for x in inorder(t.left): |
| 267 | yield x |
| 268 | yield t.label |
| 269 | for x in inorder(t.right): |
| 270 | yield x |
| 271 | \end{verbatim} |
| 272 | |
| 273 | Two other examples in \file{Lib/test/test_generators.py} produce |
| 274 | solutions for the N-Queens problem (placing $N$ queens on an $NxN$ |
| 275 | chess board so that no queen threatens another) and the Knight's Tour |
| 276 | (a route that takes a knight to every square of an $NxN$ chessboard |
| 277 | without visiting any square twice). |
| 278 | |
| 279 | The idea of generators comes from other programming languages, |
| 280 | especially Icon (\url{http://www.cs.arizona.edu/icon/}), where the |
| 281 | idea of generators is central to the language. In Icon, every |
| 282 | expression and function call behaves like a generator. One example |
| 283 | from ``An Overview of the Icon Programming Language'' at |
| 284 | \url{http://www.cs.arizona.edu/icon/docs/ipd266.htm} gives an idea of |
| 285 | what this looks like: |
| 286 | |
| 287 | \begin{verbatim} |
| 288 | sentence := "Store it in the neighboring harbor" |
| 289 | if (i := find("or", sentence)) > 5 then write(i) |
| 290 | \end{verbatim} |
| 291 | |
| 292 | The \function{find()} function returns the indexes at which the |
| 293 | substring ``or'' is found: 3, 23, 33. In the \keyword{if} statement, |
| 294 | \code{i} is first assigned a value of 3, but 3 is less than 5, so the |
| 295 | comparison fails, and Icon retries it with the second value of 23. 23 |
| 296 | is greater than 5, so the comparison now succeeds, and the code prints |
| 297 | the value 23 to the screen. |
| 298 | |
| 299 | Python doesn't go nearly as far as Icon in adopting generators as a |
| 300 | central concept. Generators are considered a new part of the core |
| 301 | Python language, but learning or using them isn't compulsory; if they |
| 302 | don't solve any problems that you have, feel free to ignore them. |
| 303 | This is different from Icon where the idea of generators is a basic |
| 304 | concept. One novel feature of Python's interface as compared to |
| 305 | Icon's is that a generator's state is represented as a concrete object |
| 306 | that can be passed around to other functions or stored in a data |
| 307 | structure. |
| 308 | |
| 309 | \begin{seealso} |
| 310 | |
| 311 | \seepep{255}{Simple Generators}{Written by Neil Schemenauer, |
| 312 | Tim Peters, Magnus Lie Hetland. Implemented mostly by Neil |
| 313 | Schemenauer, with fixes from the Python Labs crew.} |
| 314 | |
| 315 | \end{seealso} |
| 316 | |
| 317 | %====================================================================== |
Andrew M. Kuchling | a43e703 | 2001-06-27 20:32:12 +0000 | [diff] [blame] | 318 | \section{Unicode Changes} |
| 319 | |
| 320 | XXX I have to figure out what the changes mean to users. |
| 321 | (--enable-unicode configure switch) |
| 322 | |
| 323 | References: http://mail.python.org/pipermail/i18n-sig/2001-June/001107.html |
| 324 | and following thread. |
| 325 | |
Andrew M. Kuchling | 4dbf871 | 2001-07-16 02:17:14 +0000 | [diff] [blame^] | 326 | %====================================================================== |
| 327 | \section{PEP 227: Nested Scopes} |
| 328 | |
| 329 | In Python 2.1, statically nested scopes were added as an optional |
| 330 | feature, to be enabled by a \code{from __future__ import |
| 331 | nested_scopes} directive. In 2.2 nested scopes no longer need to be |
| 332 | specially enabled, but are always enabled. The rest of this section |
| 333 | is a copy of the description of nested scopes from my ``What's New in |
| 334 | Python 2.1'' document; if you read it when 2.1 came out, you can skip |
| 335 | the rest of this section. |
| 336 | |
| 337 | The largest change introduced in Python 2.1, and made complete in 2.2, |
| 338 | is to Python's scoping rules. In Python 2.0, at any given time there |
| 339 | are at most three namespaces used to look up variable names: local, |
| 340 | module-level, and the built-in namespace. This often surprised people |
| 341 | because it didn't match their intuitive expectations. For example, a |
| 342 | nested recursive function definition doesn't work: |
| 343 | |
| 344 | \begin{verbatim} |
| 345 | def f(): |
| 346 | ... |
| 347 | def g(value): |
| 348 | ... |
| 349 | return g(value-1) + 1 |
| 350 | ... |
| 351 | \end{verbatim} |
| 352 | |
| 353 | The function \function{g()} will always raise a \exception{NameError} |
| 354 | exception, because the binding of the name \samp{g} isn't in either |
| 355 | its local namespace or in the module-level namespace. This isn't much |
| 356 | of a problem in practice (how often do you recursively define interior |
| 357 | functions like this?), but this also made using the \keyword{lambda} |
| 358 | statement clumsier, and this was a problem in practice. In code which |
| 359 | uses \keyword{lambda} you can often find local variables being copied |
| 360 | by passing them as the default values of arguments. |
| 361 | |
| 362 | \begin{verbatim} |
| 363 | def find(self, name): |
| 364 | "Return list of any entries equal to 'name'" |
| 365 | L = filter(lambda x, name=name: x == name, |
| 366 | self.list_attribute) |
| 367 | return L |
| 368 | \end{verbatim} |
| 369 | |
| 370 | The readability of Python code written in a strongly functional style |
| 371 | suffers greatly as a result. |
| 372 | |
| 373 | The most significant change to Python 2.2 is that static scoping has |
| 374 | been added to the language to fix this problem. As a first effect, |
| 375 | the \code{name=name} default argument is now unnecessary in the above |
| 376 | example. Put simply, when a given variable name is not assigned a |
| 377 | value within a function (by an assignment, or the \keyword{def}, |
| 378 | \keyword{class}, or \keyword{import} statements), references to the |
| 379 | variable will be looked up in the local namespace of the enclosing |
| 380 | scope. A more detailed explanation of the rules, and a dissection of |
| 381 | the implementation, can be found in the PEP. |
| 382 | |
| 383 | This change may cause some compatibility problems for code where the |
| 384 | same variable name is used both at the module level and as a local |
| 385 | variable within a function that contains further function definitions. |
| 386 | This seems rather unlikely though, since such code would have been |
| 387 | pretty confusing to read in the first place. |
| 388 | |
| 389 | One side effect of the change is that the \code{from \var{module} |
| 390 | import *} and \keyword{exec} statements have been made illegal inside |
| 391 | a function scope under certain conditions. The Python reference |
| 392 | manual has said all along that \code{from \var{module} import *} is |
| 393 | only legal at the top level of a module, but the CPython interpreter |
| 394 | has never enforced this before. As part of the implementation of |
| 395 | nested scopes, the compiler which turns Python source into bytecodes |
| 396 | has to generate different code to access variables in a containing |
| 397 | scope. \code{from \var{module} import *} and \keyword{exec} make it |
| 398 | impossible for the compiler to figure this out, because they add names |
| 399 | to the local namespace that are unknowable at compile time. |
| 400 | Therefore, if a function contains function definitions or |
| 401 | \keyword{lambda} expressions with free variables, the compiler will |
| 402 | flag this by raising a \exception{SyntaxError} exception. |
| 403 | |
| 404 | To make the preceding explanation a bit clearer, here's an example: |
| 405 | |
| 406 | \begin{verbatim} |
| 407 | x = 1 |
| 408 | def f(): |
| 409 | # The next line is a syntax error |
| 410 | exec 'x=2' |
| 411 | def g(): |
| 412 | return x |
| 413 | \end{verbatim} |
| 414 | |
| 415 | Line 4 containing the \keyword{exec} statement is a syntax error, |
| 416 | since \keyword{exec} would define a new local variable named \samp{x} |
| 417 | whose value should be accessed by \function{g()}. |
| 418 | |
| 419 | This shouldn't be much of a limitation, since \keyword{exec} is rarely |
| 420 | used in most Python code (and when it is used, it's often a sign of a |
| 421 | poor design anyway). |
| 422 | ======= |
| 423 | %\end{seealso} |
| 424 | |
| 425 | \begin{seealso} |
| 426 | |
| 427 | \seepep{227}{Statically Nested Scopes}{Written and implemented by |
| 428 | Jeremy Hylton.} |
| 429 | |
| 430 | \end{seealso} |
| 431 | |
Andrew M. Kuchling | a43e703 | 2001-06-27 20:32:12 +0000 | [diff] [blame] | 432 | |
| 433 | %====================================================================== |
Andrew M. Kuchling | a8defaa | 2001-05-05 16:37:29 +0000 | [diff] [blame] | 434 | \section{New and Improved Modules} |
| 435 | |
| 436 | \begin{itemize} |
| 437 | |
Andrew M. Kuchling | 4dbf871 | 2001-07-16 02:17:14 +0000 | [diff] [blame^] | 438 | \item The \module{xmlrpclib} module was contributed to the standard |
| 439 | library by Fredrik Lundh. It provides support for writing XML-RPC |
| 440 | clients; XML-RPC is a simple remote procedure call protocol built on |
| 441 | top of HTTP and XML. For example, the following snippet retrieves a |
| 442 | list of RSS channels from the O'Reilly Network, and then retrieves a |
| 443 | list of the recent headlines for one channel: |
| 444 | |
| 445 | \begin{verbatim} |
| 446 | import xmlrpclib |
| 447 | s = xmlrpclib.Server( |
| 448 | 'http://www.oreillynet.com/meerkat/xml-rpc/server.php') |
| 449 | channels = s.meerkat.getChannels() |
| 450 | # channels is a list of dictionaries, like this: |
| 451 | # [{'id': 4, 'title': 'Freshmeat Daily News'} |
| 452 | # {'id': 190, 'title': '32Bits Online'}, |
| 453 | # {'id': 4549, 'title': '3DGamers'}, ... ] |
| 454 | |
| 455 | # Get the items for one channel |
| 456 | items = s.meerkat.getItems( {'channel': 4} ) |
| 457 | |
| 458 | # 'items' is another list of dictionaries, like this: |
| 459 | # [{'link': 'http://freshmeat.net/releases/52719/', |
| 460 | # 'description': 'A utility which converts HTML to XSL FO.', |
| 461 | # 'title': 'html2fo 0.3 (Default)'}, ... ] |
| 462 | \end{verbatim} |
| 463 | |
| 464 | See \url{http://www.xmlrpc.com} for more information about XML-RPC. |
| 465 | |
| 466 | \item The \module{socket} module can be compiled to support IPv6; |
| 467 | specify the \code{--enable-ipv6} option to Python's configure |
| 468 | script. (Contributed by Jun-ichiro ``itojun'' Hagino.) |
| 469 | |
| 470 | \item Two new format characters were added to the \module{struct} |
| 471 | module for 64-bit integers on platforms that support the C |
| 472 | \ctype{long long} type. \samp{q} is for a signed 64-bit integer, |
| 473 | and \samp{Q} is for an unsigned one. The value is returned in |
| 474 | Python's long integer type. (Contributed by Tim Peters.) |
| 475 | |
| 476 | \item In the interpreter's interactive mode, there's a new built-in |
| 477 | function \function{help()}, that uses the \module{pydoc} module |
| 478 | introduced in Python 2.1 to provide interactive. |
| 479 | \code{help(\var{object})} displays any available help text about |
| 480 | \var{object}. \code{help()} with no argument puts you in an online |
| 481 | help utility, where you can enter the names of functions, classes, |
| 482 | or modules to read their help text. |
| 483 | (Contributed by Guido van Rossum, using Ka-Ping Yee's \module{pydoc} module.) |
| 484 | |
| 485 | \item Various bugfixes and performance improvements have been made |
| 486 | to the SRE engine underlying the \module{re} module. For example, |
| 487 | \function{re.sub()} will now use \function{string.replace()} |
| 488 | automatically when the pattern and its replacement are both just |
| 489 | literal strings without regex metacharacters. Another contributed |
| 490 | patch speeds up certain Unicode character ranges by a factor of |
| 491 | two. (SRE is maintained by Fredrik Lundh. The BIGCHARSET patch |
| 492 | was contributed by Martin von L\"owis.) |
| 493 | |
| 494 | \item The \module{imaplib} module now has support for the IMAP |
| 495 | NAMESPACE extension defined in \rfc{2342}. (Contributed by Michel |
| 496 | Pelletier.) |
| 497 | |
Andrew M. Kuchling | a8defaa | 2001-05-05 16:37:29 +0000 | [diff] [blame] | 498 | |
| 499 | \end{itemize} |
| 500 | |
| 501 | |
| 502 | %====================================================================== |
| 503 | \section{Other Changes and Fixes} |
| 504 | |
Andrew M. Kuchling | 4dbf871 | 2001-07-16 02:17:14 +0000 | [diff] [blame^] | 505 | As usual there were a bunch of other improvements and bugfixes |
| 506 | scattered throughout the source tree. A search through the CVS change |
| 507 | logs finds there were XXX patches applied, and XXX bugs fixed; both |
| 508 | figures are likely to be underestimates. Some of the more notable |
| 509 | changes are: |
Andrew M. Kuchling | a8defaa | 2001-05-05 16:37:29 +0000 | [diff] [blame] | 510 | |
| 511 | \begin{itemize} |
| 512 | |
Andrew M. Kuchling | a8defaa | 2001-05-05 16:37:29 +0000 | [diff] [blame] | 513 | \item XXX C API: Reorganization of object calling |
| 514 | |
Andrew M. Kuchling | 3b923fc | 2001-05-19 19:35:46 +0000 | [diff] [blame] | 515 | \item XXX .encode(), .decode() string methods. Interesting new codecs such |
Andrew M. Kuchling | 4dbf871 | 2001-07-16 02:17:14 +0000 | [diff] [blame^] | 516 | as zlib. |
Andrew M. Kuchling | 3b923fc | 2001-05-19 19:35:46 +0000 | [diff] [blame] | 517 | |
Andrew M. Kuchling | 4dbf871 | 2001-07-16 02:17:14 +0000 | [diff] [blame^] | 518 | \item MacOS code now in main CVS tree. |
| 519 | |
| 520 | \item SF patch \#418147 Fixes to allow compiling w/ Borland, from Stephen Hansen. |
| 521 | |
| 522 | \item Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465. |
| 523 | |
| 524 | \item Lots of patches to dictionaries; measure performance improvement, if any. |
| 525 | |
| 526 | \item Patch \#430754: Makes ftpmirror.py .netrc aware |
| 527 | |
| 528 | \item Fix bug reported by Tim Peters on python-dev: |
| 529 | |
| 530 | Keyword arguments passed to builtin functions that don't take them are |
| 531 | ignored. |
| 532 | |
| 533 | >>> {}.clear(x=2) |
| 534 | >>> |
| 535 | |
| 536 | instead of |
| 537 | |
| 538 | >>> {}.clear(x=2) |
| 539 | Traceback (most recent call last): |
| 540 | File "<stdin>", line 1, in ? |
| 541 | TypeError: clear() takes no keyword arguments |
| 542 | |
| 543 | \item Make the license GPL-compatible. |
| 544 | |
| 545 | \item This change adds two new C-level APIs: PyEval_SetProfile() and |
| 546 | PyEval_SetTrace(). These can be used to install profile and trace |
| 547 | functions implemented in C, which can operate at much higher speeds |
| 548 | than Python-based functions. The overhead for calling a C-based |
| 549 | profile function is a very small fraction of a percent of the overhead |
| 550 | involved in calling a Python-based function. |
| 551 | |
| 552 | The machinery required to call a Python-based profile or trace |
| 553 | function been moved to sysmodule.c, where sys.setprofile() and |
| 554 | sys.setprofile() simply become users of the new interface. |
| 555 | |
| 556 | \item 'Advanced' xrange() features now deprecated: repeat, slice, |
| 557 | contains, tolist(), and the start/stop/step attributes. This includes |
| 558 | removing the 4th ('repeat') argument to PyRange_New(). |
| 559 | |
| 560 | |
| 561 | \item The call_object() function, originally in ceval.c, begins a new life |
Andrew M. Kuchling | a8defaa | 2001-05-05 16:37:29 +0000 | [diff] [blame] | 562 | %as the official API PyObject_Call(). It is also much simplified: all |
| 563 | %it does is call the tp_call slot, or raise an exception if that's |
| 564 | %NULL. |
| 565 | |
| 566 | %The subsidiary functions (call_eval_code2(), call_cfunction(), |
| 567 | %call_instance(), and call_method()) have all been moved to the file |
| 568 | %implementing their particular object type, renamed according to the |
| 569 | %local convention, and added to the type's tp_call slot. Note that |
| 570 | %call_eval_code2() became function_call(); the tp_slot for class |
| 571 | %objects now simply points to PyInstance_New(), which already has the |
| 572 | %correct signature. |
| 573 | |
| 574 | %Because of these moves, there are some more new APIs that expose |
| 575 | %helpers in ceval.c that are now needed outside: PyEval_GetFuncName(), |
| 576 | %PyEval_GetFuncDesc(), PyEval_EvalCodeEx() (formerly get_func_name(), |
| 577 | %get_func_desc(), and eval_code2(). |
| 578 | |
| 579 | \end{itemize} |
| 580 | |
| 581 | |
| 582 | |
| 583 | %====================================================================== |
| 584 | \section{Acknowledgements} |
| 585 | |
| 586 | The author would like to thank the following people for offering |
| 587 | suggestions on various drafts of this article: No one yet. |
| 588 | |
| 589 | \end{document} |