@@ -63,7 +63,7 @@ what it can, adding compatibility functions in a
63
63
usages that will become unsupported in 3.0.
64
64
65
65
Some significant new packages have been added to the standard library,
66
- such as the :mod: `multiprocessing ` and :mod: `jsonlib ` modules, but
66
+ such as the :mod: `multiprocessing ` and :mod: `json ` modules, but
67
67
there aren't many new features that aren't related to Python 3.0 in
68
68
some way.
69
69
@@ -623,7 +623,7 @@ versa.)
623
623
Two other classes, :class: `Pool ` and :class: `Manager `, provide
624
624
higher-level interfaces. :class: `Pool ` will create a fixed number of
625
625
worker processes, and requests can then be distributed to the workers
626
- by calling :meth: `apply ` or `apply_async ` to add a single request,
626
+ by calling :meth: `apply ` or :meth: `apply_async ` to add a single request,
627
627
and :meth: `map ` or :meth: `map_async ` to add a number of
628
628
requests. The following code uses a :class: `Pool ` to spread requests
629
629
across 5 worker processes and retrieve a list of results::
@@ -977,10 +977,10 @@ sequence of bytes::
977
977
bytearray(b'ABC')
978
978
>>> b = bytearray(u'\u21ef\u3244', 'utf-8')
979
979
>>> b
980
- bytearray(b'\xe2\x87\xaf \xe3\x89\x84')
980
+ bytearray(b'\xe2\x87\xaf\xe3\x89\x84')
981
981
>>> b[0] = '\xe3'
982
982
>>> b
983
- bytearray(b'\xe3\x87\xaf \xe3\x89\x84')
983
+ bytearray(b'\xe3\x87\xaf\xe3\x89\x84')
984
984
>>> unicode(str(b), 'utf-8')
985
985
u'\u31ef \u3244'
986
986
@@ -1975,7 +1975,7 @@ changes, or look through the Subversion logs for all the details.
1975
1975
1976
1976
* A new function in the :mod: `heapq ` module, ``merge(iter1, iter2, ...) ``,
1977
1977
takes any number of iterables returning data in sorted
1978
- order, and returns a new iterator that returns the contents of all
1978
+ order, and returns a new generator that returns the contents of all
1979
1979
the iterators, also in sorted order. For example::
1980
1980
1981
1981
heapq.merge([1, 3, 5, 9], [2, 8, 16]) ->
@@ -2014,56 +2014,56 @@ changes, or look through the Subversion logs for all the details.
2014
2014
others, the missing values are set to *fillvalue *. For example::
2015
2015
2016
2016
itertools.izip_longest([1,2,3], [1,2,3,4,5]) ->
2017
- [ (1, 1), (2, 2), (3, 3), (None, 4), (None, 5)]
2017
+ (1, 1), (2, 2), (3, 3), (None, 4), (None, 5)
2018
2018
2019
2019
``product(iter1, iter2, ..., [repeat=N]) `` returns the Cartesian product
2020
2020
of the supplied iterables, a set of tuples containing
2021
2021
every possible combination of the elements returned from each iterable. ::
2022
2022
2023
2023
itertools.product([1,2,3], [4,5,6]) ->
2024
- [ (1, 4), (1, 5), (1, 6),
2024
+ (1, 4), (1, 5), (1, 6),
2025
2025
(2, 4), (2, 5), (2, 6),
2026
- (3, 4), (3, 5), (3, 6)]
2026
+ (3, 4), (3, 5), (3, 6)
2027
2027
2028
2028
The optional *repeat * keyword argument is used for taking the
2029
2029
product of an iterable or a set of iterables with themselves,
2030
2030
repeated *N * times. With a single iterable argument, *N *-tuples
2031
2031
are returned::
2032
2032
2033
- itertools.product([1,2], repeat=3)) ->
2034
- [ (1, 1, 1), (1, 1, 2), (1, 2, 1), (1, 2, 2),
2035
- (2, 1, 1), (2, 1, 2), (2, 2, 1), (2, 2, 2)]
2033
+ itertools.product([1,2], repeat=3) ->
2034
+ (1, 1, 1), (1, 1, 2), (1, 2, 1), (1, 2, 2),
2035
+ (2, 1, 1), (2, 1, 2), (2, 2, 1), (2, 2, 2)
2036
2036
2037
2037
With two iterables, *2N *-tuples are returned. ::
2038
2038
2039
- itertools( product([1,2], [3,4], repeat=2) ->
2040
- [ (1, 3, 1, 3), (1, 3, 1, 4), (1, 3, 2, 3), (1, 3, 2, 4),
2039
+ itertools. product([1,2], [3,4], repeat=2) ->
2040
+ (1, 3, 1, 3), (1, 3, 1, 4), (1, 3, 2, 3), (1, 3, 2, 4),
2041
2041
(1, 4, 1, 3), (1, 4, 1, 4), (1, 4, 2, 3), (1, 4, 2, 4),
2042
2042
(2, 3, 1, 3), (2, 3, 1, 4), (2, 3, 2, 3), (2, 3, 2, 4),
2043
- (2, 4, 1, 3), (2, 4, 1, 4), (2, 4, 2, 3), (2, 4, 2, 4)]
2043
+ (2, 4, 1, 3), (2, 4, 1, 4), (2, 4, 2, 3), (2, 4, 2, 4)
2044
2044
2045
2045
``combinations(iterable, r) `` returns sub-sequences of length *r * from
2046
2046
the elements of *iterable *. ::
2047
2047
2048
2048
itertools.combinations('123', 2) ->
2049
- [ ('1', '2'), ('1', '3'), ('2', '3')]
2049
+ ('1', '2'), ('1', '3'), ('2', '3')
2050
2050
2051
2051
itertools.combinations('123', 3) ->
2052
- [ ('1', '2', '3')]
2052
+ ('1', '2', '3')
2053
2053
2054
2054
itertools.combinations('1234', 3) ->
2055
- [ ('1', '2', '3'), ('1', '2', '4'), ('1', '3', '4'),
2056
- ('2', '3', '4')]
2055
+ ('1', '2', '3'), ('1', '2', '4'), ('1', '3', '4'),
2056
+ ('2', '3', '4')
2057
2057
2058
2058
``permutations(iter[, r]) `` returns all the permutations of length *r * of
2059
2059
the iterable's elements. If *r * is not specified, it will default to the
2060
2060
number of elements produced by the iterable. ::
2061
2061
2062
2062
itertools.permutations([1,2,3,4], 2) ->
2063
- [ (1, 2), (1, 3), (1, 4),
2063
+ (1, 2), (1, 3), (1, 4),
2064
2064
(2, 1), (2, 3), (2, 4),
2065
2065
(3, 1), (3, 2), (3, 4),
2066
- (4, 1), (4, 2), (4, 3)]
2066
+ (4, 1), (4, 2), (4, 3)
2067
2067
2068
2068
``itertools.chain(*iterables) `` is an existing function in
2069
2069
:mod: `itertools ` that gained a new constructor in Python 2.6.
@@ -2073,7 +2073,7 @@ changes, or look through the Subversion logs for all the details.
2073
2073
all the elements of the second, and so on. ::
2074
2074
2075
2075
chain.from_iterable([[1,2,3], [4,5,6]]) ->
2076
- [ 1, 2, 3, 4, 5, 6]
2076
+ 1, 2, 3, 4, 5, 6
2077
2077
2078
2078
(All contributed by Raymond Hettinger.)
2079
2079
@@ -2178,7 +2178,7 @@ changes, or look through the Subversion logs for all the details.
2178
2178
:const: `UF_APPEND ` to indicate that data can only be appended to the
2179
2179
file. (Contributed by M. Levinson.)
2180
2180
2181
- ``os.closerange(* low*, * high* ) `` efficiently closes all file descriptors
2181
+ ``os.closerange(low, high) `` efficiently closes all file descriptors
2182
2182
from *low * to *high *, ignoring any errors and not including *high * itself.
2183
2183
This function is now used by the :mod: `subprocess ` module to make starting
2184
2184
processes faster. (Contributed by Georg Brandl; :issue: `1663329 `.)
@@ -2311,12 +2311,12 @@ changes, or look through the Subversion logs for all the details.
2311
2311
will be ignored, not copied.
2312
2312
2313
2313
The :mod: `shutil ` module also provides an :func: `ignore_patterns `
2314
- function for use with this new parameter.
2315
- :func: ` ignore_patterns ` takes an arbitrary number of glob-style patterns
2316
- and will ignore any files and directories that match any of these patterns.
2317
- The following example copies a directory tree, but skips both
2318
- :file: `.svn ` directories and Emacs backup
2319
- files, which have names ending with '~'::
2314
+ function for use with this new parameter. :func: ` ignore_patterns `
2315
+ takes an arbitrary number of glob-style patterns and returns a
2316
+ callable that will ignore any files and directories that match any
2317
+ of these patterns. The following example copies a directory tree,
2318
+ but skips both :file: `.svn ` directories and Emacs backup files,
2319
+ which have names ending with '~'::
2320
2320
2321
2321
shutil.copytree('Doc/library', '/tmp/library',
2322
2322
ignore=shutil.ignore_patterns('*~', '.svn'))
@@ -2523,13 +2523,15 @@ changes, or look through the Subversion logs for all the details.
2523
2523
2524
2524
(Contributed by Dwayne Bailey; :issue: `1581073 `.)
2525
2525
2526
- * The :mod: `threading ` module API is being changed to use properties such as
2527
- :attr: `daemon ` instead of :meth: `setDaemon ` and :meth: `isDaemon ` methods, and
2528
- some methods have been renamed to use underscores instead of camel-case; for
2529
- example, the :meth: `activeCount ` method is renamed to :meth: `active_count `.
2530
- The 2.6 version of the module supports the same properties and renamed
2531
- methods, but doesn't remove the old methods. 3.0 also fully supports both
2532
- APIs, and a date for the deprecation of the old APIs has not been set yet.
2526
+ * The :mod: `threading ` module API is being changed to use properties
2527
+ such as :attr: `daemon ` instead of :meth: `setDaemon ` and
2528
+ :meth: `isDaemon ` methods, and some methods have been renamed to use
2529
+ underscores instead of camel-case; for example, the
2530
+ :meth: `activeCount ` method is renamed to :meth: `active_count `. Both
2531
+ the 2.6 and 3.0 versions of the module support the same properties
2532
+ and renamed methods, but don't remove the old methods. No date has been set
2533
+ for the deprecation of the old APIs in Python 3.x; the old APIs won't
2534
+ be removed in any 2.x version.
2533
2535
(Carried out by several people, most notably Benjamin Peterson.)
2534
2536
2535
2537
The :mod: `threading ` module's :class: `Thread ` objects
@@ -2735,15 +2737,15 @@ of these built-in functions that can be imported when writing
2735
2737
2736
2738
The functions in this module currently include:
2737
2739
2738
- * ``ascii(* obj* ) ``: equivalent to :func: `repr `. In Python 3.0,
2740
+ * ``ascii(obj) ``: equivalent to :func: `repr `. In Python 3.0,
2739
2741
:func: `repr ` will return a Unicode string, while :func: `ascii ` will
2740
2742
return a pure ASCII bytestring.
2741
2743
2742
- * ``filter(* predicate*, * iterable* ) ``,
2743
- ``map(* func*, * iterable1* , ...) ``: the 3.0 versions
2744
+ * ``filter(predicate, iterable) ``,
2745
+ ``map(func, iterable1, ...) ``: the 3.0 versions
2744
2746
return iterators, unlike the 2.x built-ins which return lists.
2745
2747
2746
- * ``hex(* value* ) ``, ``oct(* value* ) ``: instead of calling the
2748
+ * ``hex(value) ``, ``oct(value) ``: instead of calling the
2747
2749
:meth: `__hex__ ` or :meth: `__oct__ ` methods, these versions will
2748
2750
call the :meth: `__index__ ` method and convert the result to hexadecimal
2749
2751
or octal. :func: `oct ` will use the new ``0o `` notation for its
@@ -3210,7 +3212,8 @@ that may require changes to your code:
3210
3212
Acknowledgements
3211
3213
================
3212
3214
3213
- The author would like to thank the following people for offering suggestions,
3214
- corrections and assistance with various drafts of this article:
3215
- Georg Brandl, Steve Brown, Nick Coghlan, Jim Jewett, Antoine Pitrou.
3215
+ The author would like to thank the following people for offering
3216
+ suggestions, corrections and assistance with various drafts of this
3217
+ article: Georg Brandl, Steve Brown, Nick Coghlan, Jim Jewett, Kent
3218
+ Johnson, Chris Lambacher, Antoine Pitrou.
3216
3219
0 commit comments