Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1330)

Delta Between Two Patch Sets: Doc/whatsnew/2.4.rst

Issue 15527: Double parens in functions references
Left Patch Set: Created 9 months, 2 weeks ago
Right Patch Set: Created 9 months, 2 weeks ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Doc/whatsnew/2.3.rst ('k') | Doc/whatsnew/2.5.rst » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 **************************** 1 ****************************
2 What's New in Python 2.4 2 What's New in Python 2.4
3 **************************** 3 ****************************
4 4
5 :Author: A.M. Kuchling 5 :Author: A.M. Kuchling
6 6
7 .. |release| replace:: 1.02 7 .. |release| replace:: 1.02
8 8
9 .. $Id: whatsnew24.tex 54632 2007-03-31 11:59:54Z georg.brandl $ 9 .. $Id: whatsnew24.tex 54632 2007-03-31 11:59:54Z georg.brandl $
10 .. Don't write extensive text for new sections; I'll do that. 10 .. Don't write extensive text for new sections; I'll do that.
(...skipping 19 matching lines...) Expand all
30 implementation and design rationale. 30 implementation and design rationale.
31 31
32 .. ====================================================================== 32 .. ======================================================================
33 33
34 34
35 PEP 218: Built-In Set Objects 35 PEP 218: Built-In Set Objects
36 ============================= 36 =============================
37 37
38 Python 2.3 introduced the :mod:`sets` module. C implementations of set data 38 Python 2.3 introduced the :mod:`sets` module. C implementations of set data
39 types have now been added to the Python core as two new built-in types, 39 types have now been added to the Python core as two new built-in types,
40 :func:`set(iterable) <set>` and :func:`frozenset(iterable) <frozenset>`. They p rovide high speed 40 ``set(iterable)`` and ``frozenset(iterable)``. They provide high speed
41 operations for membership testing, for eliminating duplicates from sequences, 41 operations for membership testing, for eliminating duplicates from sequences,
42 and for mathematical operations like unions, intersections, differences, and 42 and for mathematical operations like unions, intersections, differences, and
43 symmetric differences. :: 43 symmetric differences. ::
44 44
45 >>> a = set('abracadabra') # form a set from a string 45 >>> a = set('abracadabra') # form a set from a string
46 >>> 'z' in a # fast membership testing 46 >>> 'z' in a # fast membership testing
47 False 47 False
48 >>> a # unique letters in a 48 >>> a # unique letters in a
49 set(['a', 'r', 'b', 'c', 'd']) 49 set(['a', 'r', 'b', 'c', 'd'])
50 >>> ''.join(a) # convert back into a string 50 >>> ''.join(a) # convert back into a string
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 339
340 http://www.python.org/moin/PythonDecoratorLibrary 340 http://www.python.org/moin/PythonDecoratorLibrary
341 This Wiki page contains several examples of decorators. 341 This Wiki page contains several examples of decorators.
342 342
343 .. ====================================================================== 343 .. ======================================================================
344 344
345 345
346 PEP 322: Reverse Iteration 346 PEP 322: Reverse Iteration
347 ========================== 347 ==========================
348 348
349 A new built-in function, :func:`reversed(seq) <reversed>`, takes a sequence and returns an 349 A new built-in function, ``reversed(seq)``, takes a sequence and returns an
350 iterator that loops over the elements of the sequence in reverse order. :: 350 iterator that loops over the elements of the sequence in reverse order. ::
351 351
352 >>> for i in reversed(xrange(1,4)): 352 >>> for i in reversed(xrange(1,4)):
353 ... print i 353 ... print i
354 ... 354 ...
355 3 355 3
356 2 356 2
357 1 357 1
358 358
359 Compared to extended slicing, such as ``range(1,4)[::-1]``, :func:`reversed` is 359 Compared to extended slicing, such as ``range(1,4)[::-1]``, :func:`reversed` is
(...skipping 17 matching lines...) Expand all
377 Written and implemented by Raymond Hettinger. 377 Written and implemented by Raymond Hettinger.
378 378
379 .. ====================================================================== 379 .. ======================================================================
380 380
381 381
382 PEP 324: New subprocess Module 382 PEP 324: New subprocess Module
383 ============================== 383 ==============================
384 384
385 The standard library provides a number of ways to execute a subprocess, offering 385 The standard library provides a number of ways to execute a subprocess, offering
386 different features and different levels of complexity. 386 different features and different levels of complexity.
387 :func:`os.system(command) <os.system>` is easy to use, but slow (it runs a shell process 387 ``os.system(command)`` is easy to use, but slow (it runs a shell process
388 which executes the command) and dangerous (you have to be careful about escaping 388 which executes the command) and dangerous (you have to be careful about escaping
389 the shell's metacharacters). The :mod:`popen2` module offers classes that can 389 the shell's metacharacters). The :mod:`popen2` module offers classes that can
390 capture standard output and standard error from the subprocess, but the naming 390 capture standard output and standard error from the subprocess, but the naming
391 is confusing. The :mod:`subprocess` module cleans this up, providing a unified 391 is confusing. The :mod:`subprocess` module cleans this up, providing a unified
392 interface that offers all the features you might need. 392 interface that offers all the features you might need.
393 393
394 Instead of :mod:`popen2`'s collection of classes, :mod:`subprocess` contains a 394 Instead of :mod:`popen2`'s collection of classes, :mod:`subprocess` contains a
395 single class called :class:`Popen` whose constructor supports a number of 395 single class called :class:`Popen` whose constructor supports a number of
396 different keyword arguments. :: 396 different keyword arguments. ::
397 397
(...skipping 23 matching lines...) Expand all
421 421
422 * *env* is a dictionary specifying environment variables. 422 * *env* is a dictionary specifying environment variables.
423 423
424 * *preexec_fn* is a function that gets called before the child is started. 424 * *preexec_fn* is a function that gets called before the child is started.
425 425
426 * *universal_newlines* opens the child's input and output using Python's 426 * *universal_newlines* opens the child's input and output using Python's
427 universal newline feature. 427 universal newline feature.
428 428
429 Once you've created the :class:`Popen` instance, you can call its :meth:`wait` 429 Once you've created the :class:`Popen` instance, you can call its :meth:`wait`
430 method to pause until the subprocess has exited, :meth:`poll` to check if it's 430 method to pause until the subprocess has exited, :meth:`poll` to check if it's
431 exited without pausing, or :meth:`communicate(data) <subprocess.Popen.communica te>` to send the string *data* 431 exited without pausing, or ``communicate(data)`` to send the string *data*
432 to the subprocess's standard input. :meth:`communicate(data) <subprocess.Popen .communicate>` then reads any 432 to the subprocess's standard input. ``communicate(data)`` then reads any
433 data that the subprocess has sent to its standard output or standard error, 433 data that the subprocess has sent to its standard output or standard error,
434 returning a tuple ``(stdout_data, stderr_data)``. 434 returning a tuple ``(stdout_data, stderr_data)``.
435 435
436 :func:`call` is a shortcut that passes its arguments along to the :class:`Popen` 436 :func:`call` is a shortcut that passes its arguments along to the :class:`Popen`
437 constructor, waits for the command to complete, and returns the status code of 437 constructor, waits for the command to complete, and returns the status code of
438 the subprocess. It can serve as a safer analog to :func:`os.system`:: 438 the subprocess. It can serve as a safer analog to :func:`os.system`::
439 439
440 sts = subprocess.call(['dpkg', '-i', '/tmp/new-package.deb']) 440 sts = subprocess.call(['dpkg', '-i', '/tmp/new-package.deb'])
441 if sts == 0: 441 if sts == 0:
442 # Success 442 # Success
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 library's :c:func:`atof` function. 739 library's :c:func:`atof` function.
740 740
741 Not setting the numeric locale caused trouble for extensions that used third- 741 Not setting the numeric locale caused trouble for extensions that used third-
742 party C libraries, however, because they wouldn't have the correct locale set. 742 party C libraries, however, because they wouldn't have the correct locale set.
743 The motivating example was GTK+, whose user interface widgets weren't displaying 743 The motivating example was GTK+, whose user interface widgets weren't displaying
744 numbers in the current locale. 744 numbers in the current locale.
745 745
746 The solution described in the PEP is to add three new functions to the Python 746 The solution described in the PEP is to add three new functions to the Python
747 API that perform ASCII-only conversions, ignoring the locale setting: 747 API that perform ASCII-only conversions, ignoring the locale setting:
748 748
749 * :c:func:`PyOS_ascii_strtod(str, ptr) <PyOS_ascii_strtod>` and :c:func:`PyOS_a scii_atof(str, ptr) <PyOS_ascii_atof>` 749 * ``PyOS_ascii_strtod(str, ptr)`` and ``PyOS_ascii_atof(str, ptr)``
750 both convert a string to a C :c:type:`double`. 750 both convert a string to a C :c:type:`double`.
751 751
752 * :c:func:`PyOS_ascii_formatd(buffer, buf_len, format, d) <PyOS_ascii_formatd>` converts a 752 * ``PyOS_ascii_formatd(buffer, buf_len, format, d)`` converts a
753 :c:type:`double` to an ASCII string. 753 :c:type:`double` to an ASCII string.
754 754
755 The code for these functions came from the GLib library 755 The code for these functions came from the GLib library
756 (http://library.gnome.org/devel/glib/stable/), whose developers kindly 756 (http://library.gnome.org/devel/glib/stable/), whose developers kindly
757 relicensed the relevant functions and donated them to the Python Software 757 relicensed the relevant functions and donated them to the Python Software
758 Foundation. The :mod:`locale` module can now change the numeric locale, 758 Foundation. The :mod:`locale` module can now change the numeric locale,
759 letting extensions such as GTK+ produce the correct results. 759 letting extensions such as GTK+ produce the correct results.
760 760
761 761
762 .. seealso:: 762 .. seealso::
763 763
764 :pep:`331` - Locale-Independent Float/String Conversions 764 :pep:`331` - Locale-Independent Float/String Conversions
765 Written by Christian R. Reis, and implemented by Gustavo Carneiro. 765 Written by Christian R. Reis, and implemented by Gustavo Carneiro.
766 766
767 .. ====================================================================== 767 .. ======================================================================
768 768
769 769
770 Other Language Changes 770 Other Language Changes
771 ====================== 771 ======================
772 772
773 Here are all of the changes that Python 2.4 makes to the core Python language. 773 Here are all of the changes that Python 2.4 makes to the core Python language.
774 774
775 * Decorators for functions and methods were added (:pep:`318`). 775 * Decorators for functions and methods were added (:pep:`318`).
776 776
777 * Built-in :func:`set` and :func:`frozenset` types were added (:pep:`218`). 777 * Built-in :func:`set` and :func:`frozenset` types were added (:pep:`218`).
778 Other new built-ins include the :func:`reversed(seq) <reversed>` function (:pe p:`322`). 778 Other new built-ins include the ``reversed(seq)`` function (:pep:`322`).
779 779
780 * Generator expressions were added (:pep:`289`). 780 * Generator expressions were added (:pep:`289`).
781 781
782 * Certain numeric expressions no longer return values restricted to 32 or 64 782 * Certain numeric expressions no longer return values restricted to 32 or 64
783 bits (:pep:`237`). 783 bits (:pep:`237`).
784 784
785 * You can now put parentheses around the list of names in a ``from module import 785 * You can now put parentheses around the list of names in a ``from module import
786 names`` statement (:pep:`328`). 786 names`` statement (:pep:`328`).
787 787
788 * The :meth:`dict.update` method now accepts the same argument forms as the 788 * The :meth:`dict.update` method now accepts the same argument forms as the
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 L.reverse()``, you can now write ``L.sort(reverse=True)``. 847 L.reverse()``, you can now write ``L.sort(reverse=True)``.
848 848
849 The results of sorting are now guaranteed to be stable. This means that two 849 The results of sorting are now guaranteed to be stable. This means that two
850 entries with equal keys will be returned in the same order as they were input. 850 entries with equal keys will be returned in the same order as they were input.
851 For example, you can sort a list of people by name, and then sort the list by 851 For example, you can sort a list of people by name, and then sort the list by
852 age, resulting in a list sorted by age where people with the same age are in 852 age, resulting in a list sorted by age where people with the same age are in
853 name-sorted order. 853 name-sorted order.
854 854
855 (All changes to :meth:`sort` contributed by Raymond Hettinger.) 855 (All changes to :meth:`sort` contributed by Raymond Hettinger.)
856 856
857 * There is a new built-in function :func:`sorted(iterable) <sorted>` that works like the 857 * There is a new built-in function ``sorted(iterable)`` that works like the
858 in-place :meth:`list.sort` method but can be used in expressions. The 858 in-place :meth:`list.sort` method but can be used in expressions. The
859 differences are: 859 differences are:
860 860
861 * the input may be any iterable; 861 * the input may be any iterable;
862 862
863 * a newly formed copy is sorted, leaving the original intact; and 863 * a newly formed copy is sorted, leaving the original intact; and
864 864
865 * the expression returns the new sorted copy 865 * the expression returns the new sorted copy
866 866
867 :: 867 ::
(...skipping 20 matching lines...) Expand all
888 (Contributed by Raymond Hettinger.) 888 (Contributed by Raymond Hettinger.)
889 889
890 * Integer operations will no longer trigger an :exc:`OverflowWarning`. The 890 * Integer operations will no longer trigger an :exc:`OverflowWarning`. The
891 :exc:`OverflowWarning` warning will disappear in Python 2.5. 891 :exc:`OverflowWarning` warning will disappear in Python 2.5.
892 892
893 * The interpreter gained a new switch, :option:`-m`, that takes a name, searches 893 * The interpreter gained a new switch, :option:`-m`, that takes a name, searches
894 for the corresponding module on ``sys.path``, and runs the module as a script . 894 for the corresponding module on ``sys.path``, and runs the module as a script .
895 For example, you can now run the Python profiler with ``python -m profile``. 895 For example, you can now run the Python profiler with ``python -m profile``.
896 (Contributed by Nick Coghlan.) 896 (Contributed by Nick Coghlan.)
897 897
898 * The :func:`eval(expr, globals, locals) <eval>` and :func:`execfile(filename, g lobals, 898 * The ``eval(expr, globals, locals)`` and ``execfile(filename, globals,
899 locals) <execfile>` functions and the ``exec`` statement now accept any mappin g type 899 locals)`` functions and the ``exec`` statement now accept any mapping type
900 for the *locals* parameter. Previously this had to be a regular Python 900 for the *locals* parameter. Previously this had to be a regular Python
901 dictionary. (Contributed by Raymond Hettinger.) 901 dictionary. (Contributed by Raymond Hettinger.)
902 902
903 * The :func:`zip` built-in function and :func:`itertools.izip` now return an 903 * The :func:`zip` built-in function and :func:`itertools.izip` now return an
904 empty list if called with no arguments. Previously they raised a 904 empty list if called with no arguments. Previously they raised a
905 :exc:`TypeError` exception. This makes them more suitable for use with variab le 905 :exc:`TypeError` exception. This makes them more suitable for use with variab le
906 length argument lists:: 906 length argument lists::
907 907
908 >>> def transpose(array): 908 >>> def transpose(array):
909 ... return zip(*array) 909 ... return zip(*array)
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 * The :mod:`httplib` module now contains constants for HTTP status codes defined 1080 * The :mod:`httplib` module now contains constants for HTTP status codes defined
1081 in various HTTP-related RFC documents. Constants have names such as 1081 in various HTTP-related RFC documents. Constants have names such as
1082 :const:`OK`, :const:`CREATED`, :const:`CONTINUE`, and 1082 :const:`OK`, :const:`CREATED`, :const:`CONTINUE`, and
1083 :const:`MOVED_PERMANENTLY`; use pydoc to get a full list. (Contributed by 1083 :const:`MOVED_PERMANENTLY`; use pydoc to get a full list. (Contributed by
1084 Andrew Eland.) 1084 Andrew Eland.)
1085 1085
1086 * The :mod:`imaplib` module now supports IMAP's THREAD command (contributed by 1086 * The :mod:`imaplib` module now supports IMAP's THREAD command (contributed by
1087 Yves Dionne) and new :meth:`deleteacl` and :meth:`myrights` methods (contribut ed 1087 Yves Dionne) and new :meth:`deleteacl` and :meth:`myrights` methods (contribut ed
1088 by Arnaud Mazin). 1088 by Arnaud Mazin).
1089 1089
1090 * The :mod:`itertools` module gained a :func:`groupby(iterable[, *func*]) <itert ools.groupby>` 1090 * The :mod:`itertools` module gained a ``groupby(iterable[, *func*])``
1091 function. *iterable* is something that can be iterated over to return a stream 1091 function. *iterable* is something that can be iterated over to return a stream
1092 of elements, and the optional *func* parameter is a function that takes an 1092 of elements, and the optional *func* parameter is a function that takes an
1093 element and returns a key value; if omitted, the key is simply the element 1093 element and returns a key value; if omitted, the key is simply the element
1094 itself. :func:`groupby` then groups the elements into subsequences which have 1094 itself. :func:`groupby` then groups the elements into subsequences which have
1095 matching values of the key, and returns a series of 2-tuples containing the ke y 1095 matching values of the key, and returns a series of 2-tuples containing the ke y
1096 value and an iterator over the subsequence. 1096 value and an iterator over the subsequence.
1097 1097
1098 Here's an example to make this clearer. The *key* function simply returns 1098 Here's an example to make this clearer. The *key* function simply returns
1099 whether a number is even or odd, so the result of :func:`groupby` is to return 1099 whether a number is even or odd, so the result of :func:`groupby` is to return
1100 consecutive runs of odd or even numbers. :: 1100 consecutive runs of odd or even numbers. ::
(...skipping 28 matching lines...) Expand all
1129 r ['r', 'r'] 1129 r ['r', 'r']
1130 >>> # List unique letters 1130 >>> # List unique letters
1131 >>> [k for k, g in groupby(letters)] 1131 >>> [k for k, g in groupby(letters)]
1132 ['a', 'b', 'c', 'd', 'r'] 1132 ['a', 'b', 'c', 'd', 'r']
1133 >>> # Count letter occurrences 1133 >>> # Count letter occurrences
1134 >>> [(k, len(list(g))) for k, g in groupby(letters)] 1134 >>> [(k, len(list(g))) for k, g in groupby(letters)]
1135 [('a', 5), ('b', 2), ('c', 1), ('d', 1), ('r', 2)] 1135 [('a', 5), ('b', 2), ('c', 1), ('d', 1), ('r', 2)]
1136 1136
1137 (Contributed by Hye-Shik Chang.) 1137 (Contributed by Hye-Shik Chang.)
1138 1138
1139 * :mod:`itertools` also gained a function named :func:`tee(iterator, N) <itertoo ls.tee>` that 1139 * :mod:`itertools` also gained a function named ``tee(iterator, N)`` that
1140 returns *N* independent iterators that replicate *iterator*. If *N* is omitte d, 1140 returns *N* independent iterators that replicate *iterator*. If *N* is omitte d,
1141 the default is 2. :: 1141 the default is 2. ::
1142 1142
1143 >>> L = [1,2,3] 1143 >>> L = [1,2,3]
1144 >>> i1, i2 = itertools.tee(L) 1144 >>> i1, i2 = itertools.tee(L)
1145 >>> i1,i2 1145 >>> i1,i2
1146 (<itertools.tee object at 0x402c2080>, <itertools.tee object at 0x402c2090> ) 1146 (<itertools.tee object at 0x402c2080>, <itertools.tee object at 0x402c2090> )
1147 >>> list(i1) # Run the first iterator to exhaustion 1147 >>> list(i1) # Run the first iterator to exhaustion
1148 [1, 2, 3] 1148 [1, 2, 3]
1149 >>> list(i2) # Run the second iterator to exhaustion 1149 >>> list(i2) # Run the second iterator to exhaustion
(...skipping 17 matching lines...) Expand all
1167 :func:`basicConfig` function to simplify log configuration. The default 1167 :func:`basicConfig` function to simplify log configuration. The default
1168 behavior is to log messages to standard error, but various keyword arguments c an 1168 behavior is to log messages to standard error, but various keyword arguments c an
1169 be specified to log to a particular file, change the logging format, or set th e 1169 be specified to log to a particular file, change the logging format, or set th e
1170 logging level. For example:: 1170 logging level. For example::
1171 1171
1172 import logging 1172 import logging
1173 logging.basicConfig(filename='/var/log/application.log', 1173 logging.basicConfig(filename='/var/log/application.log',
1174 level=0, # Log all messages 1174 level=0, # Log all messages
1175 format='%(levelname):%(process):%(thread):%(message)') 1175 format='%(levelname):%(process):%(thread):%(message)')
1176 1176
1177 Other additions to the :mod:`logging` package include a :meth:`log(level, msg) <logging.Logger.log>` 1177 Other additions to the :mod:`logging` package include a ``log(level, msg)``
1178 convenience method, as well as a :class:`TimedRotatingFileHandler` class that 1178 convenience method, as well as a :class:`TimedRotatingFileHandler` class that
1179 rotates its log files at a timed interval. The module already had 1179 rotates its log files at a timed interval. The module already had
1180 :class:`RotatingFileHandler`, which rotated logs once the file exceeded a 1180 :class:`RotatingFileHandler`, which rotated logs once the file exceeded a
1181 certain size. Both classes derive from a new :class:`BaseRotatingHandler` cla ss 1181 certain size. Both classes derive from a new :class:`BaseRotatingHandler` cla ss
1182 that can be used to implement other rotating handlers. 1182 that can be used to implement other rotating handlers.
1183 1183
1184 (Changes implemented by Vinay Sajip.) 1184 (Changes implemented by Vinay Sajip.)
1185 1185
1186 * The :mod:`marshal` module now shares interned strings on unpacking a data 1186 * The :mod:`marshal` module now shares interned strings on unpacking a data
1187 structure. This may shrink the size of certain pickle strings, but the primar y 1187 structure. This may shrink the size of certain pickle strings, but the primar y
1188 effect is to make :file:`.pyc` files significantly smaller. (Contributed by 1188 effect is to make :file:`.pyc` files significantly smaller. (Contributed by
1189 Martin von Löwis.) 1189 Martin von Löwis.)
1190 1190
1191 * The :mod:`nntplib` module's :class:`NNTP` class gained :meth:`description` and 1191 * The :mod:`nntplib` module's :class:`NNTP` class gained :meth:`description` and
1192 :meth:`descriptions` methods to retrieve newsgroup descriptions for a single 1192 :meth:`descriptions` methods to retrieve newsgroup descriptions for a single
1193 group or for a range of groups. (Contributed by Jürgen A. Erhard.) 1193 group or for a range of groups. (Contributed by Jürgen A. Erhard.)
1194 1194
1195 * Two new functions were added to the :mod:`operator` module, 1195 * Two new functions were added to the :mod:`operator` module,
1196 :func:`attrgetter(attr) <operator.attrgetter>` and :func:`itemgetter(index) <o perator.itemgetter>`. Both functions return 1196 ``attrgetter(attr)`` and ``itemgetter(index)``. Both functions return
1197 callables that take a single argument and return the corresponding attribute o r 1197 callables that take a single argument and return the corresponding attribute o r
1198 item; these callables make excellent data extractors when used with :func:`map ` 1198 item; these callables make excellent data extractors when used with :func:`map `
1199 or :func:`sorted`. For example:: 1199 or :func:`sorted`. For example::
1200 1200
1201 >>> L = [('c', 2), ('d', 1), ('a', 4), ('b', 3)] 1201 >>> L = [('c', 2), ('d', 1), ('a', 4), ('b', 3)]
1202 >>> map(operator.itemgetter(0), L) 1202 >>> map(operator.itemgetter(0), L)
1203 ['c', 'd', 'a', 'b'] 1203 ['c', 'd', 'a', 'b']
1204 >>> map(operator.itemgetter(1), L) 1204 >>> map(operator.itemgetter(1), L)
1205 [2, 1, 4, 3] 1205 [2, 1, 4, 3]
1206 >>> sorted(L, key=operator.itemgetter(1)) # Sort list by second tuple item 1206 >>> sorted(L, key=operator.itemgetter(1)) # Sort list by second tuple item
1207 [('d', 1), ('c', 2), ('b', 3), ('a', 4)] 1207 [('d', 1), ('c', 2), ('b', 3), ('a', 4)]
1208 1208
1209 (Contributed by Raymond Hettinger.) 1209 (Contributed by Raymond Hettinger.)
1210 1210
1211 * The :mod:`optparse` module was updated in various ways. The module now passes 1211 * The :mod:`optparse` module was updated in various ways. The module now passes
1212 its messages through :func:`gettext.gettext`, making it possible to 1212 its messages through :func:`gettext.gettext`, making it possible to
1213 internationalize Optik's help and error messages. Help messages for options c an 1213 internationalize Optik's help and error messages. Help messages for options c an
1214 now include the string ``'%default'``, which will be replaced by the option's 1214 now include the string ``'%default'``, which will be replaced by the option's
1215 default value. (Contributed by Greg Ward.) 1215 default value. (Contributed by Greg Ward.)
1216 1216
1217 * The long-term plan is to deprecate the :mod:`rfc822` module in some future 1217 * The long-term plan is to deprecate the :mod:`rfc822` module in some future
1218 Python release in favor of the :mod:`email` package. To this end, the 1218 Python release in favor of the :mod:`email` package. To this end, the
1219 :func:`email.Utils.formatdate` function has been changed to make it usable as a 1219 :func:`email.Utils.formatdate` function has been changed to make it usable as a
1220 replacement for :func:`rfc822.formatdate`. You may want to write new e-mail 1220 replacement for :func:`rfc822.formatdate`. You may want to write new e-mail
1221 processing code with this in mind. (Change implemented by Anthony Baxter.) 1221 processing code with this in mind. (Change implemented by Anthony Baxter.)
1222 1222
1223 * A new :func:`urandom(n) <os.urandom>` function was added to the :mod:`os` modu le, returning 1223 * A new ``urandom(n)`` function was added to the :mod:`os` module, returning
1224 a string containing *n* bytes of random data. This function provides access t o 1224 a string containing *n* bytes of random data. This function provides access t o
1225 platform-specific sources of randomness such as :file:`/dev/urandom` on Linux or 1225 platform-specific sources of randomness such as :file:`/dev/urandom` on Linux or
1226 the Windows CryptoAPI. (Contributed by Trevor Perrin.) 1226 the Windows CryptoAPI. (Contributed by Trevor Perrin.)
1227 1227
1228 * Another new function: :func:`os.path.lexists(path) <os.path.lexists>` returns true if the file 1228 * Another new function: ``os.path.lexists(path)`` returns true if the file
1229 specified by *path* exists, whether or not it's a symbolic link. This differs 1229 specified by *path* exists, whether or not it's a symbolic link. This differs
1230 from the existing :func:`os.path.exists(path) <os.path.exists>` function, whic h returns false if 1230 from the existing ``os.path.exists(path)`` function, which returns false if
1231 *path* is a symlink that points to a destination that doesn't exist. 1231 *path* is a symlink that points to a destination that doesn't exist.
1232 (Contributed by Beni Cherniavsky.) 1232 (Contributed by Beni Cherniavsky.)
1233 1233
1234 * A new :func:`getsid` function was added to the :mod:`posix` module that 1234 * A new :func:`getsid` function was added to the :mod:`posix` module that
1235 underlies the :mod:`os` module. (Contributed by J. Raynor.) 1235 underlies the :mod:`os` module. (Contributed by J. Raynor.)
1236 1236
1237 * The :mod:`poplib` module now supports POP over SSL. (Contributed by Hector 1237 * The :mod:`poplib` module now supports POP over SSL. (Contributed by Hector
1238 Urtubia.) 1238 Urtubia.)
1239 1239
1240 * The :mod:`profile` module can now profile C extension functions. (Contributed 1240 * The :mod:`profile` module can now profile C extension functions. (Contributed
1241 by Nick Bastin.) 1241 by Nick Bastin.)
1242 1242
1243 * The :mod:`random` module has a new method called :meth:`getrandbits(N) <random .getrandbits>` that 1243 * The :mod:`random` module has a new method called ``getrandbits(N)`` that
1244 returns a long integer *N* bits in length. The existing :meth:`randrange` 1244 returns a long integer *N* bits in length. The existing :meth:`randrange`
1245 method now uses :meth:`getrandbits` where appropriate, making generation of 1245 method now uses :meth:`getrandbits` where appropriate, making generation of
1246 arbitrarily large random numbers more efficient. (Contributed by Raymond 1246 arbitrarily large random numbers more efficient. (Contributed by Raymond
1247 Hettinger.) 1247 Hettinger.)
1248 1248
1249 * The regular expression language accepted by the :mod:`re` module was extended 1249 * The regular expression language accepted by the :mod:`re` module was extended
1250 with simple conditional expressions, written as ``(?(group)A|B)``. *group* is 1250 with simple conditional expressions, written as ``(?(group)A|B)``. *group* is
1251 either a numeric group ID or a group name defined with ``(?P<group>...)`` 1251 either a numeric group ID or a group name defined with ``(?P<group>...)``
1252 earlier in the expression. If the specified group matched, the regular 1252 earlier in the expression. If the specified group matched, the regular
1253 expression pattern *A* will be tested against the string; if the group didn't 1253 expression pattern *A* will be tested against the string; if the group didn't
1254 match, the pattern *B* will be used instead. (Contributed by Gustavo Niemeyer. ) 1254 match, the pattern *B* will be used instead. (Contributed by Gustavo Niemeyer. )
1255 1255
1256 * The :mod:`re` module is also no longer recursive, thanks to a massive amount 1256 * The :mod:`re` module is also no longer recursive, thanks to a massive amount
1257 of work by Gustavo Niemeyer. In a recursive regular expression engine, certai n 1257 of work by Gustavo Niemeyer. In a recursive regular expression engine, certai n
1258 patterns result in a large amount of C stack space being consumed, and it was 1258 patterns result in a large amount of C stack space being consumed, and it was
1259 possible to overflow the stack. For example, if you matched a 30000-byte strin g 1259 possible to overflow the stack. For example, if you matched a 30000-byte strin g
1260 of ``a`` characters against the expression ``(a|b)+``, one stack frame was 1260 of ``a`` characters against the expression ``(a|b)+``, one stack frame was
1261 consumed per character. Python 2.3 tried to check for stack overflow and rais e 1261 consumed per character. Python 2.3 tried to check for stack overflow and rais e
1262 a :exc:`RuntimeError` exception, but certain patterns could sidestep the 1262 a :exc:`RuntimeError` exception, but certain patterns could sidestep the
1263 checking and if you were unlucky Python could segfault. Python 2.4's regular 1263 checking and if you were unlucky Python could segfault. Python 2.4's regular
1264 expression engine can match this pattern without problems. 1264 expression engine can match this pattern without problems.
1265 1265
1266 * The :mod:`signal` module now performs tighter error-checking on the parameters 1266 * The :mod:`signal` module now performs tighter error-checking on the parameters
1267 to the :func:`signal.signal` function. For example, you can't set a handler o n 1267 to the :func:`signal.signal` function. For example, you can't set a handler o n
1268 the :const:`SIGKILL` signal; previous versions of Python would quietly accept 1268 the :const:`SIGKILL` signal; previous versions of Python would quietly accept
1269 this, but 2.4 will raise a :exc:`RuntimeError` exception. 1269 this, but 2.4 will raise a :exc:`RuntimeError` exception.
1270 1270
1271 * Two new functions were added to the :mod:`socket` module. :func:`socketpair` 1271 * Two new functions were added to the :mod:`socket` module. :func:`socketpair`
1272 returns a pair of connected sockets and :func:`getservbyport(port) <socket.get servbyport>` looks up the 1272 returns a pair of connected sockets and ``getservbyport(port)`` looks up the
1273 service name for a given port number. (Contributed by Dave Cole and Barry 1273 service name for a given port number. (Contributed by Dave Cole and Barry
1274 Warsaw.) 1274 Warsaw.)
1275 1275
1276 * The :func:`sys.exitfunc` function has been deprecated. Code should be using 1276 * The :func:`sys.exitfunc` function has been deprecated. Code should be using
1277 the existing :mod:`atexit` module, which correctly handles calling multiple ex it 1277 the existing :mod:`atexit` module, which correctly handles calling multiple ex it
1278 functions. Eventually :func:`sys.exitfunc` will become a purely internal 1278 functions. Eventually :func:`sys.exitfunc` will become a purely internal
1279 interface, accessed only by :mod:`atexit`. 1279 interface, accessed only by :mod:`atexit`.
1280 1280
1281 * The :mod:`tarfile` module now generates GNU-format tar files by default. 1281 * The :mod:`tarfile` module now generates GNU-format tar files by default.
1282 (Contributed by Lars Gustaebel.) 1282 (Contributed by Lars Gustaebel.)
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1444 1444
1445 Some of the changes to Python's build process and to the C API are: 1445 Some of the changes to Python's build process and to the C API are:
1446 1446
1447 * Three new convenience macros were added for common return values from 1447 * Three new convenience macros were added for common return values from
1448 extension functions: :c:macro:`Py_RETURN_NONE`, :c:macro:`Py_RETURN_TRUE`, and 1448 extension functions: :c:macro:`Py_RETURN_NONE`, :c:macro:`Py_RETURN_TRUE`, and
1449 :c:macro:`Py_RETURN_FALSE`. (Contributed by Brett Cannon.) 1449 :c:macro:`Py_RETURN_FALSE`. (Contributed by Brett Cannon.)
1450 1450
1451 * Another new macro, :c:macro:`Py_CLEAR(obj)`, decreases the reference count of 1451 * Another new macro, :c:macro:`Py_CLEAR(obj)`, decreases the reference count of
1452 *obj* and sets *obj* to the null pointer. (Contributed by Jim Fulton.) 1452 *obj* and sets *obj* to the null pointer. (Contributed by Jim Fulton.)
1453 1453
1454 * A new function, :c:func:`PyTuple_Pack(N, obj1, obj2, ..., objN) <PyTuple_Pack> `, constructs 1454 * A new function, ``PyTuple_Pack(N, obj1, obj2, ..., objN)``, constructs
1455 tuples from a variable length argument list of Python objects. (Contributed b y 1455 tuples from a variable length argument list of Python objects. (Contributed b y
1456 Raymond Hettinger.) 1456 Raymond Hettinger.)
1457 1457
1458 * A new function, :c:func:`PyDict_Contains(d, k) <PyDict_Contains>`, implements fast dictionary 1458 * A new function, ``PyDict_Contains(d, k)``, implements fast dictionary
1459 lookups without masking exceptions raised during the look-up process. 1459 lookups without masking exceptions raised during the look-up process.
1460 (Contributed by Raymond Hettinger.) 1460 (Contributed by Raymond Hettinger.)
1461 1461
1462 * The :c:macro:`Py_IS_NAN(X)` macro returns 1 if its float or double argument 1462 * The :c:macro:`Py_IS_NAN(X)` macro returns 1 if its float or double argument
1463 *X* is a NaN. (Contributed by Tim Peters.) 1463 *X* is a NaN. (Contributed by Tim Peters.)
1464 1464
1465 * C code can avoid unnecessary locking by using the new 1465 * C code can avoid unnecessary locking by using the new
1466 :c:func:`PyEval_ThreadsInitialized` function to tell if any thread operations 1466 :c:func:`PyEval_ThreadsInitialized` function to tell if any thread operations
1467 have been performed. If this function returns false, no lock operations are 1467 have been performed. If this function returns false, no lock operations are
1468 needed. (Contributed by Nick Coghlan.) 1468 needed. (Contributed by Nick Coghlan.)
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1551 .. _24acks: 1551 .. _24acks:
1552 1552
1553 Acknowledgements 1553 Acknowledgements
1554 ================ 1554 ================
1555 1555
1556 The author would like to thank the following people for offering suggestions, 1556 The author would like to thank the following people for offering suggestions,
1557 corrections and assistance with various drafts of this article: Koray Can, 1557 corrections and assistance with various drafts of this article: Koray Can,
1558 Hye-Shik Chang, Michael Dyck, Raymond Hettinger, Brian Hurt, Hamish Lawson, 1558 Hye-Shik Chang, Michael Dyck, Raymond Hettinger, Brian Hurt, Hamish Lawson,
1559 Fredrik Lundh, Sean Reifschneider, Sadruddin Rejeb. 1559 Fredrik Lundh, Sean Reifschneider, Sadruddin Rejeb.
1560 1560
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7