2007-08-15 11:28:22 -03:00
|
|
|
.. XXX: reference/datamodel and this have quite a few overlaps!
|
|
|
|
|
|
|
|
|
|
|
|
.. _bltin-types:
|
|
|
|
|
|
|
|
**************
|
|
|
|
Built-in Types
|
|
|
|
**************
|
|
|
|
|
|
|
|
The following sections describe the standard types that are built into the
|
|
|
|
interpreter.
|
|
|
|
|
|
|
|
.. index:: pair: built-in; types
|
|
|
|
|
2009-12-19 14:22:15 -04:00
|
|
|
The principal built-in types are numerics, sequences, mappings, classes,
|
2007-08-15 11:28:22 -03:00
|
|
|
instances and exceptions.
|
|
|
|
|
2011-10-08 13:32:40 -03:00
|
|
|
Some collection classes are mutable. The methods that add, subtract, or
|
|
|
|
rearrange their members in place, and don't return a specific item, never return
|
|
|
|
the collection instance itself but ``None``.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
Some operations are supported by several object types; in particular,
|
|
|
|
practically all objects can be compared, tested for truth value, and converted
|
|
|
|
to a string (with the :func:`repr` function or the slightly different
|
|
|
|
:func:`str` function). The latter function is implicitly used when an object is
|
|
|
|
written by the :func:`print` function.
|
|
|
|
|
|
|
|
|
|
|
|
.. _truth:
|
|
|
|
|
|
|
|
Truth Value Testing
|
|
|
|
===================
|
|
|
|
|
|
|
|
.. index::
|
|
|
|
statement: if
|
|
|
|
statement: while
|
|
|
|
pair: truth; value
|
|
|
|
pair: Boolean; operations
|
|
|
|
single: false
|
|
|
|
|
|
|
|
Any object can be tested for truth value, for use in an :keyword:`if` or
|
2017-07-29 19:56:06 -03:00
|
|
|
:keyword:`while` condition or as operand of the Boolean operations below.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-07-29 19:56:06 -03:00
|
|
|
.. index:: single: true
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-07-29 19:56:06 -03:00
|
|
|
By default, an object is considered true unless its class defines either a
|
|
|
|
:meth:`__bool__` method that returns ``False`` or a :meth:`__len__` method that
|
|
|
|
returns zero, when called with the object. [1]_ Here are most of the built-in
|
|
|
|
objects considered false:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-07-29 19:56:06 -03:00
|
|
|
.. index::
|
|
|
|
single: None (Built-in object)
|
|
|
|
single: False (Built-in object)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-07-29 19:56:06 -03:00
|
|
|
* constants defined to be false: ``None`` and ``False``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-07-29 19:56:06 -03:00
|
|
|
* zero of any numeric type: ``0``, ``0.0``, ``0j``, ``Decimal(0)``,
|
|
|
|
``Fraction(0, 1)``
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-07-29 19:56:06 -03:00
|
|
|
* empty sequences and collections: ``''``, ``()``, ``[]``, ``{}``, ``set()``,
|
|
|
|
``range(0)``
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. index::
|
|
|
|
operator: or
|
|
|
|
operator: and
|
|
|
|
single: False
|
|
|
|
single: True
|
|
|
|
|
|
|
|
Operations and built-in functions that have a Boolean result always return ``0``
|
|
|
|
or ``False`` for false and ``1`` or ``True`` for true, unless otherwise stated.
|
|
|
|
(Important exception: the Boolean operations ``or`` and ``and`` always return
|
|
|
|
one of their operands.)
|
|
|
|
|
|
|
|
|
|
|
|
.. _boolean:
|
|
|
|
|
|
|
|
Boolean Operations --- :keyword:`and`, :keyword:`or`, :keyword:`not`
|
|
|
|
====================================================================
|
|
|
|
|
|
|
|
.. index:: pair: Boolean; operations
|
|
|
|
|
|
|
|
These are the Boolean operations, ordered by ascending priority:
|
|
|
|
|
|
|
|
+-------------+---------------------------------+-------+
|
|
|
|
| Operation | Result | Notes |
|
|
|
|
+=============+=================================+=======+
|
|
|
|
| ``x or y`` | if *x* is false, then *y*, else | \(1) |
|
|
|
|
| | *x* | |
|
|
|
|
+-------------+---------------------------------+-------+
|
|
|
|
| ``x and y`` | if *x* is false, then *x*, else | \(2) |
|
|
|
|
| | *y* | |
|
|
|
|
+-------------+---------------------------------+-------+
|
|
|
|
| ``not x`` | if *x* is false, then ``True``, | \(3) |
|
|
|
|
| | else ``False`` | |
|
|
|
|
+-------------+---------------------------------+-------+
|
|
|
|
|
|
|
|
.. index::
|
|
|
|
operator: and
|
|
|
|
operator: or
|
|
|
|
operator: not
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
|
|
|
|
(1)
|
|
|
|
This is a short-circuit operator, so it only evaluates the second
|
2017-03-03 17:24:13 -04:00
|
|
|
argument if the first one is false.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
(2)
|
|
|
|
This is a short-circuit operator, so it only evaluates the second
|
2017-03-03 17:24:13 -04:00
|
|
|
argument if the first one is true.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
(3)
|
|
|
|
``not`` has a lower priority than non-Boolean operators, so ``not a == b`` is
|
|
|
|
interpreted as ``not (a == b)``, and ``a == not b`` is a syntax error.
|
|
|
|
|
|
|
|
|
|
|
|
.. _stdcomparisons:
|
|
|
|
|
|
|
|
Comparisons
|
|
|
|
===========
|
|
|
|
|
2007-08-31 14:17:17 -03:00
|
|
|
.. index::
|
Merged revisions 74074,74077,74111,74188,74192-74193,74200,74252-74253,74258-74261 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74074 | georg.brandl | 2009-07-18 05:03:10 -0400 (Sat, 18 Jul 2009) | 1 line
#6513: fix example code: warning categories are classes, not instances.
........
r74077 | georg.brandl | 2009-07-18 05:43:40 -0400 (Sat, 18 Jul 2009) | 1 line
#6489: fix an ambiguity in getiterator() documentation.
........
r74111 | benjamin.peterson | 2009-07-20 09:30:10 -0400 (Mon, 20 Jul 2009) | 1 line
remove docs for deprecated -p option
........
r74188 | benjamin.peterson | 2009-07-23 10:25:31 -0400 (Thu, 23 Jul 2009) | 1 line
use bools
........
r74192 | georg.brandl | 2009-07-24 12:28:38 -0400 (Fri, 24 Jul 2009) | 1 line
Fix arg types of et#.
........
r74193 | georg.brandl | 2009-07-24 12:46:38 -0400 (Fri, 24 Jul 2009) | 1 line
Dont put "void" in signature for nullary functions.
........
r74200 | georg.brandl | 2009-07-25 09:02:15 -0400 (Sat, 25 Jul 2009) | 1 line
#6571: add index entries for more operators.
........
r74252 | georg.brandl | 2009-07-29 12:06:31 -0400 (Wed, 29 Jul 2009) | 1 line
#6593: fix link targets.
........
r74253 | georg.brandl | 2009-07-29 12:09:17 -0400 (Wed, 29 Jul 2009) | 1 line
#6591: add reference to ioctl in fcntl module for platforms other than Windows.
........
r74258 | georg.brandl | 2009-07-29 12:57:05 -0400 (Wed, 29 Jul 2009) | 1 line
Add a link to readline, and mention IPython and bpython.
........
r74259 | georg.brandl | 2009-07-29 13:07:21 -0400 (Wed, 29 Jul 2009) | 1 line
Fix some markup and small factual glitches found by M. Markert.
........
r74260 | georg.brandl | 2009-07-29 13:15:20 -0400 (Wed, 29 Jul 2009) | 1 line
Fix a few markup glitches.
........
r74261 | georg.brandl | 2009-07-29 13:50:25 -0400 (Wed, 29 Jul 2009) | 1 line
Rewrite the section about classes a bit; mostly tidbits, and a larger update to the section about "private" variables to reflect the Pythonic consensus better.
........
2009-07-29 16:54:39 -03:00
|
|
|
pair: chaining; comparisons
|
2007-08-31 14:17:17 -03:00
|
|
|
pair: operator; comparison
|
|
|
|
operator: ==
|
|
|
|
operator: <
|
|
|
|
operator: <=
|
Merged revisions 74074,74077,74111,74188,74192-74193,74200,74252-74253,74258-74261 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74074 | georg.brandl | 2009-07-18 05:03:10 -0400 (Sat, 18 Jul 2009) | 1 line
#6513: fix example code: warning categories are classes, not instances.
........
r74077 | georg.brandl | 2009-07-18 05:43:40 -0400 (Sat, 18 Jul 2009) | 1 line
#6489: fix an ambiguity in getiterator() documentation.
........
r74111 | benjamin.peterson | 2009-07-20 09:30:10 -0400 (Mon, 20 Jul 2009) | 1 line
remove docs for deprecated -p option
........
r74188 | benjamin.peterson | 2009-07-23 10:25:31 -0400 (Thu, 23 Jul 2009) | 1 line
use bools
........
r74192 | georg.brandl | 2009-07-24 12:28:38 -0400 (Fri, 24 Jul 2009) | 1 line
Fix arg types of et#.
........
r74193 | georg.brandl | 2009-07-24 12:46:38 -0400 (Fri, 24 Jul 2009) | 1 line
Dont put "void" in signature for nullary functions.
........
r74200 | georg.brandl | 2009-07-25 09:02:15 -0400 (Sat, 25 Jul 2009) | 1 line
#6571: add index entries for more operators.
........
r74252 | georg.brandl | 2009-07-29 12:06:31 -0400 (Wed, 29 Jul 2009) | 1 line
#6593: fix link targets.
........
r74253 | georg.brandl | 2009-07-29 12:09:17 -0400 (Wed, 29 Jul 2009) | 1 line
#6591: add reference to ioctl in fcntl module for platforms other than Windows.
........
r74258 | georg.brandl | 2009-07-29 12:57:05 -0400 (Wed, 29 Jul 2009) | 1 line
Add a link to readline, and mention IPython and bpython.
........
r74259 | georg.brandl | 2009-07-29 13:07:21 -0400 (Wed, 29 Jul 2009) | 1 line
Fix some markup and small factual glitches found by M. Markert.
........
r74260 | georg.brandl | 2009-07-29 13:15:20 -0400 (Wed, 29 Jul 2009) | 1 line
Fix a few markup glitches.
........
r74261 | georg.brandl | 2009-07-29 13:50:25 -0400 (Wed, 29 Jul 2009) | 1 line
Rewrite the section about classes a bit; mostly tidbits, and a larger update to the section about "private" variables to reflect the Pythonic consensus better.
........
2009-07-29 16:54:39 -03:00
|
|
|
operator: >
|
2007-08-31 14:17:17 -03:00
|
|
|
operator: >=
|
|
|
|
operator: !=
|
|
|
|
operator: is
|
|
|
|
operator: is not
|
|
|
|
|
Merged revisions 74074,74077,74111,74188,74192-74193,74200,74252-74253,74258-74261 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74074 | georg.brandl | 2009-07-18 05:03:10 -0400 (Sat, 18 Jul 2009) | 1 line
#6513: fix example code: warning categories are classes, not instances.
........
r74077 | georg.brandl | 2009-07-18 05:43:40 -0400 (Sat, 18 Jul 2009) | 1 line
#6489: fix an ambiguity in getiterator() documentation.
........
r74111 | benjamin.peterson | 2009-07-20 09:30:10 -0400 (Mon, 20 Jul 2009) | 1 line
remove docs for deprecated -p option
........
r74188 | benjamin.peterson | 2009-07-23 10:25:31 -0400 (Thu, 23 Jul 2009) | 1 line
use bools
........
r74192 | georg.brandl | 2009-07-24 12:28:38 -0400 (Fri, 24 Jul 2009) | 1 line
Fix arg types of et#.
........
r74193 | georg.brandl | 2009-07-24 12:46:38 -0400 (Fri, 24 Jul 2009) | 1 line
Dont put "void" in signature for nullary functions.
........
r74200 | georg.brandl | 2009-07-25 09:02:15 -0400 (Sat, 25 Jul 2009) | 1 line
#6571: add index entries for more operators.
........
r74252 | georg.brandl | 2009-07-29 12:06:31 -0400 (Wed, 29 Jul 2009) | 1 line
#6593: fix link targets.
........
r74253 | georg.brandl | 2009-07-29 12:09:17 -0400 (Wed, 29 Jul 2009) | 1 line
#6591: add reference to ioctl in fcntl module for platforms other than Windows.
........
r74258 | georg.brandl | 2009-07-29 12:57:05 -0400 (Wed, 29 Jul 2009) | 1 line
Add a link to readline, and mention IPython and bpython.
........
r74259 | georg.brandl | 2009-07-29 13:07:21 -0400 (Wed, 29 Jul 2009) | 1 line
Fix some markup and small factual glitches found by M. Markert.
........
r74260 | georg.brandl | 2009-07-29 13:15:20 -0400 (Wed, 29 Jul 2009) | 1 line
Fix a few markup glitches.
........
r74261 | georg.brandl | 2009-07-29 13:50:25 -0400 (Wed, 29 Jul 2009) | 1 line
Rewrite the section about classes a bit; mostly tidbits, and a larger update to the section about "private" variables to reflect the Pythonic consensus better.
........
2009-07-29 16:54:39 -03:00
|
|
|
There are eight comparison operations in Python. They all have the same
|
|
|
|
priority (which is higher than that of the Boolean operations). Comparisons can
|
|
|
|
be chained arbitrarily; for example, ``x < y <= z`` is equivalent to ``x < y and
|
|
|
|
y <= z``, except that *y* is evaluated only once (but in both cases *z* is not
|
|
|
|
evaluated at all when ``x < y`` is found to be false).
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
This table summarizes the comparison operations:
|
|
|
|
|
2008-01-07 05:13:03 -04:00
|
|
|
+------------+-------------------------+
|
|
|
|
| Operation | Meaning |
|
|
|
|
+============+=========================+
|
|
|
|
| ``<`` | strictly less than |
|
|
|
|
+------------+-------------------------+
|
|
|
|
| ``<=`` | less than or equal |
|
|
|
|
+------------+-------------------------+
|
|
|
|
| ``>`` | strictly greater than |
|
|
|
|
+------------+-------------------------+
|
|
|
|
| ``>=`` | greater than or equal |
|
|
|
|
+------------+-------------------------+
|
|
|
|
| ``==`` | equal |
|
|
|
|
+------------+-------------------------+
|
|
|
|
| ``!=`` | not equal |
|
|
|
|
+------------+-------------------------+
|
|
|
|
| ``is`` | object identity |
|
|
|
|
+------------+-------------------------+
|
|
|
|
| ``is not`` | negated object identity |
|
|
|
|
+------------+-------------------------+
|
Merged revisions 59605-59624 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59606 | georg.brandl | 2007-12-29 11:57:00 +0100 (Sat, 29 Dec 2007) | 2 lines
Some cleanup in the docs.
........
r59611 | martin.v.loewis | 2007-12-29 19:49:21 +0100 (Sat, 29 Dec 2007) | 2 lines
Bug #1699: Define _BSD_SOURCE only on OpenBSD.
........
r59612 | raymond.hettinger | 2007-12-29 23:09:34 +0100 (Sat, 29 Dec 2007) | 1 line
Simpler documentation for itertools.tee(). Should be backported.
........
r59613 | raymond.hettinger | 2007-12-29 23:16:24 +0100 (Sat, 29 Dec 2007) | 1 line
Improve docs for itertools.groupby(). The use of xrange(0) to create a unique object is less obvious than object().
........
r59620 | christian.heimes | 2007-12-31 15:47:07 +0100 (Mon, 31 Dec 2007) | 3 lines
Added wininst-9.0.exe executable for VS 2008
Integrated bdist_wininst into PCBuild9 directory
........
r59621 | christian.heimes | 2007-12-31 15:51:18 +0100 (Mon, 31 Dec 2007) | 1 line
Moved PCbuild directory to PC/VS7.1
........
r59622 | christian.heimes | 2007-12-31 15:59:26 +0100 (Mon, 31 Dec 2007) | 1 line
Fix paths for build bot
........
r59623 | christian.heimes | 2007-12-31 16:02:41 +0100 (Mon, 31 Dec 2007) | 1 line
Fix paths for build bot, part 2
........
r59624 | christian.heimes | 2007-12-31 16:18:55 +0100 (Mon, 31 Dec 2007) | 1 line
Renamed PCBuild9 directory to PCBuild
........
2007-12-31 12:14:33 -04:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. index::
|
|
|
|
pair: object; numeric
|
|
|
|
pair: objects; comparing
|
|
|
|
|
2007-09-28 10:39:25 -03:00
|
|
|
Objects of different types, except different numeric types, never compare equal.
|
2009-12-19 14:22:15 -04:00
|
|
|
Furthermore, some types (for example, function objects) support only a degenerate
|
2007-09-28 10:39:25 -03:00
|
|
|
notion of comparison where any two objects of that type are unequal. The ``<``,
|
|
|
|
``<=``, ``>`` and ``>=`` operators will raise a :exc:`TypeError` exception when
|
2010-03-13 05:48:39 -04:00
|
|
|
comparing a complex number with another built-in numeric type, when the objects
|
|
|
|
are of different types that cannot be compared, or in other cases where there is
|
|
|
|
no defined ordering.
|
2007-09-28 10:39:25 -03:00
|
|
|
|
2009-01-03 17:18:54 -04:00
|
|
|
.. index::
|
2007-09-28 10:39:25 -03:00
|
|
|
single: __eq__() (instance method)
|
|
|
|
single: __ne__() (instance method)
|
|
|
|
single: __lt__() (instance method)
|
|
|
|
single: __le__() (instance method)
|
|
|
|
single: __gt__() (instance method)
|
|
|
|
single: __ge__() (instance method)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-09-24 06:11:47 -03:00
|
|
|
Non-identical instances of a class normally compare as non-equal unless the
|
|
|
|
class defines the :meth:`__eq__` method.
|
2007-09-28 10:39:25 -03:00
|
|
|
|
|
|
|
Instances of a class cannot be ordered with respect to other instances of the
|
|
|
|
same class, or other types of object, unless the class defines enough of the
|
2008-09-24 06:11:47 -03:00
|
|
|
methods :meth:`__lt__`, :meth:`__le__`, :meth:`__gt__`, and :meth:`__ge__` (in
|
|
|
|
general, :meth:`__lt__` and :meth:`__eq__` are sufficient, if you want the
|
|
|
|
conventional meanings of the comparison operators).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2007-09-28 10:39:25 -03:00
|
|
|
The behavior of the :keyword:`is` and :keyword:`is not` operators cannot be
|
|
|
|
customized; also they can be applied to any two objects and never raise an
|
|
|
|
exception.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. index::
|
|
|
|
operator: in
|
|
|
|
operator: not in
|
|
|
|
|
2011-01-15 13:03:02 -04:00
|
|
|
Two more operations with the same syntactic priority, :keyword:`in` and
|
|
|
|
:keyword:`not in`, are supported only by sequence types (below).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. _typesnumeric:
|
|
|
|
|
2007-09-28 10:39:25 -03:00
|
|
|
Numeric Types --- :class:`int`, :class:`float`, :class:`complex`
|
|
|
|
================================================================
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. index::
|
|
|
|
object: numeric
|
|
|
|
object: Boolean
|
|
|
|
object: integer
|
|
|
|
object: floating point
|
|
|
|
object: complex number
|
|
|
|
pair: C; language
|
|
|
|
|
2008-07-01 12:50:04 -03:00
|
|
|
There are three distinct numeric types: :dfn:`integers`, :dfn:`floating
|
|
|
|
point numbers`, and :dfn:`complex numbers`. In addition, Booleans are a
|
|
|
|
subtype of integers. Integers have unlimited precision. Floating point
|
2010-10-06 07:11:56 -03:00
|
|
|
numbers are usually implemented using :c:type:`double` in C; information
|
2010-08-04 15:42:43 -03:00
|
|
|
about the precision and internal representation of floating point
|
|
|
|
numbers for the machine on which your program is running is available
|
|
|
|
in :data:`sys.float_info`. Complex numbers have a real and imaginary
|
|
|
|
part, which are each a floating point number. To extract these parts
|
|
|
|
from a complex number *z*, use ``z.real`` and ``z.imag``. (The standard
|
|
|
|
library includes additional numeric types, :mod:`fractions` that hold
|
|
|
|
rationals, and :mod:`decimal` that hold floating-point numbers with
|
|
|
|
user-definable precision.)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. index::
|
|
|
|
pair: numeric; literals
|
|
|
|
pair: integer; literals
|
|
|
|
pair: floating point; literals
|
|
|
|
pair: complex number; literals
|
|
|
|
pair: hexadecimal; literals
|
|
|
|
pair: octal; literals
|
2007-10-02 04:26:14 -03:00
|
|
|
pair: binary; literals
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Numbers are created by numeric literals or as the result of built-in functions
|
2007-09-28 10:39:25 -03:00
|
|
|
and operators. Unadorned integer literals (including hex, octal and binary
|
|
|
|
numbers) yield integers. Numeric literals containing a decimal point or an
|
|
|
|
exponent sign yield floating point numbers. Appending ``'j'`` or ``'J'`` to a
|
|
|
|
numeric literal yields an imaginary number (a complex number with a zero real
|
|
|
|
part) which you can add to an integer or float to get a complex number with real
|
|
|
|
and imaginary parts.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. index::
|
|
|
|
single: arithmetic
|
|
|
|
builtin: int
|
|
|
|
builtin: float
|
|
|
|
builtin: complex
|
Merged revisions 74074,74077,74111,74188,74192-74193,74200,74252-74253,74258-74261 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74074 | georg.brandl | 2009-07-18 05:03:10 -0400 (Sat, 18 Jul 2009) | 1 line
#6513: fix example code: warning categories are classes, not instances.
........
r74077 | georg.brandl | 2009-07-18 05:43:40 -0400 (Sat, 18 Jul 2009) | 1 line
#6489: fix an ambiguity in getiterator() documentation.
........
r74111 | benjamin.peterson | 2009-07-20 09:30:10 -0400 (Mon, 20 Jul 2009) | 1 line
remove docs for deprecated -p option
........
r74188 | benjamin.peterson | 2009-07-23 10:25:31 -0400 (Thu, 23 Jul 2009) | 1 line
use bools
........
r74192 | georg.brandl | 2009-07-24 12:28:38 -0400 (Fri, 24 Jul 2009) | 1 line
Fix arg types of et#.
........
r74193 | georg.brandl | 2009-07-24 12:46:38 -0400 (Fri, 24 Jul 2009) | 1 line
Dont put "void" in signature for nullary functions.
........
r74200 | georg.brandl | 2009-07-25 09:02:15 -0400 (Sat, 25 Jul 2009) | 1 line
#6571: add index entries for more operators.
........
r74252 | georg.brandl | 2009-07-29 12:06:31 -0400 (Wed, 29 Jul 2009) | 1 line
#6593: fix link targets.
........
r74253 | georg.brandl | 2009-07-29 12:09:17 -0400 (Wed, 29 Jul 2009) | 1 line
#6591: add reference to ioctl in fcntl module for platforms other than Windows.
........
r74258 | georg.brandl | 2009-07-29 12:57:05 -0400 (Wed, 29 Jul 2009) | 1 line
Add a link to readline, and mention IPython and bpython.
........
r74259 | georg.brandl | 2009-07-29 13:07:21 -0400 (Wed, 29 Jul 2009) | 1 line
Fix some markup and small factual glitches found by M. Markert.
........
r74260 | georg.brandl | 2009-07-29 13:15:20 -0400 (Wed, 29 Jul 2009) | 1 line
Fix a few markup glitches.
........
r74261 | georg.brandl | 2009-07-29 13:50:25 -0400 (Wed, 29 Jul 2009) | 1 line
Rewrite the section about classes a bit; mostly tidbits, and a larger update to the section about "private" variables to reflect the Pythonic consensus better.
........
2009-07-29 16:54:39 -03:00
|
|
|
operator: +
|
|
|
|
operator: -
|
|
|
|
operator: *
|
|
|
|
operator: /
|
|
|
|
operator: //
|
|
|
|
operator: %
|
|
|
|
operator: **
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Python fully supports mixed arithmetic: when a binary arithmetic operator has
|
|
|
|
operands of different numeric types, the operand with the "narrower" type is
|
2007-09-28 10:39:25 -03:00
|
|
|
widened to that of the other, where integer is narrower than floating point,
|
|
|
|
which is narrower than complex. Comparisons between numbers of mixed type use
|
2011-08-15 08:27:19 -03:00
|
|
|
the same rule. [2]_ The constructors :func:`int`, :func:`float`, and
|
2007-09-28 10:39:25 -03:00
|
|
|
:func:`complex` can be used to produce numbers of a specific type.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
All numeric types (except complex) support the following operations, sorted by
|
2014-10-31 05:41:46 -03:00
|
|
|
ascending priority (all numeric operations have a higher priority than
|
|
|
|
comparison operations):
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-03-22 21:33:17 -03:00
|
|
|
+---------------------+---------------------------------+---------+--------------------+
|
|
|
|
| Operation | Result | Notes | Full documentation |
|
|
|
|
+=====================+=================================+=========+====================+
|
|
|
|
| ``x + y`` | sum of *x* and *y* | | |
|
|
|
|
+---------------------+---------------------------------+---------+--------------------+
|
|
|
|
| ``x - y`` | difference of *x* and *y* | | |
|
|
|
|
+---------------------+---------------------------------+---------+--------------------+
|
|
|
|
| ``x * y`` | product of *x* and *y* | | |
|
|
|
|
+---------------------+---------------------------------+---------+--------------------+
|
|
|
|
| ``x / y`` | quotient of *x* and *y* | | |
|
|
|
|
+---------------------+---------------------------------+---------+--------------------+
|
|
|
|
| ``x // y`` | floored quotient of *x* and | \(1) | |
|
|
|
|
| | *y* | | |
|
|
|
|
+---------------------+---------------------------------+---------+--------------------+
|
|
|
|
| ``x % y`` | remainder of ``x / y`` | \(2) | |
|
|
|
|
+---------------------+---------------------------------+---------+--------------------+
|
|
|
|
| ``-x`` | *x* negated | | |
|
|
|
|
+---------------------+---------------------------------+---------+--------------------+
|
|
|
|
| ``+x`` | *x* unchanged | | |
|
|
|
|
+---------------------+---------------------------------+---------+--------------------+
|
|
|
|
| ``abs(x)`` | absolute value or magnitude of | | :func:`abs` |
|
|
|
|
| | *x* | | |
|
|
|
|
+---------------------+---------------------------------+---------+--------------------+
|
|
|
|
| ``int(x)`` | *x* converted to integer | \(3)\(6)| :func:`int` |
|
|
|
|
+---------------------+---------------------------------+---------+--------------------+
|
|
|
|
| ``float(x)`` | *x* converted to floating point | \(4)\(6)| :func:`float` |
|
|
|
|
+---------------------+---------------------------------+---------+--------------------+
|
|
|
|
| ``complex(re, im)`` | a complex number with real part | \(6) | :func:`complex` |
|
|
|
|
| | *re*, imaginary part *im*. | | |
|
|
|
|
| | *im* defaults to zero. | | |
|
|
|
|
+---------------------+---------------------------------+---------+--------------------+
|
|
|
|
| ``c.conjugate()`` | conjugate of the complex number | | |
|
|
|
|
| | *c* | | |
|
|
|
|
+---------------------+---------------------------------+---------+--------------------+
|
|
|
|
| ``divmod(x, y)`` | the pair ``(x // y, x % y)`` | \(2) | :func:`divmod` |
|
|
|
|
+---------------------+---------------------------------+---------+--------------------+
|
|
|
|
| ``pow(x, y)`` | *x* to the power *y* | \(5) | :func:`pow` |
|
|
|
|
+---------------------+---------------------------------+---------+--------------------+
|
|
|
|
| ``x ** y`` | *x* to the power *y* | \(5) | |
|
|
|
|
+---------------------+---------------------------------+---------+--------------------+
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. index::
|
|
|
|
triple: operations on; numeric; types
|
|
|
|
single: conjugate() (complex number method)
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
|
|
|
|
(1)
|
2007-09-28 10:39:25 -03:00
|
|
|
Also referred to as integer division. The resultant value is a whole
|
|
|
|
integer, though the result's type is not necessarily int. The result is
|
|
|
|
always rounded towards minus infinity: ``1//2`` is ``0``, ``(-1)//2`` is
|
|
|
|
``-1``, ``1//(-2)`` is ``-1``, and ``(-1)//(-2)`` is ``0``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
(2)
|
2007-09-28 10:39:25 -03:00
|
|
|
Not for complex numbers. Instead convert to floats using :func:`abs` if
|
|
|
|
appropriate.
|
|
|
|
|
|
|
|
(3)
|
2007-08-15 11:28:22 -03:00
|
|
|
.. index::
|
|
|
|
module: math
|
|
|
|
single: floor() (in module math)
|
|
|
|
single: ceil() (in module math)
|
Merged revisions 68288-68291,68325-68326,68338,68388,68393,68423 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r68288 | benjamin.peterson | 2009-01-03 18:39:07 -0600 (Sat, 03 Jan 2009) | 1 line
only check the actual compile() call for a SyntaxError
................
r68289 | georg.brandl | 2009-01-04 02:26:10 -0600 (Sun, 04 Jan 2009) | 2 lines
Test commit.
................
r68290 | georg.brandl | 2009-01-04 04:23:49 -0600 (Sun, 04 Jan 2009) | 4 lines
Add "suspicious" builder which finds leftover markup in the HTML files.
Patch by Gabriel Genellina.
................
r68291 | georg.brandl | 2009-01-04 04:24:09 -0600 (Sun, 04 Jan 2009) | 2 lines
Fix two issues found by the suspicious builder.
................
r68325 | benjamin.peterson | 2009-01-04 16:00:18 -0600 (Sun, 04 Jan 2009) | 1 line
use Jinja 2.1.1
................
r68326 | georg.brandl | 2009-01-04 16:03:10 -0600 (Sun, 04 Jan 2009) | 2 lines
Update make.bat.
................
r68338 | neal.norwitz | 2009-01-04 21:57:25 -0600 (Sun, 04 Jan 2009) | 1 line
Make sure to checkout any new packages
................
r68388 | benjamin.peterson | 2009-01-07 21:39:46 -0600 (Wed, 07 Jan 2009) | 1 line
string exceptions are gone
................
r68393 | benjamin.peterson | 2009-01-07 22:01:00 -0600 (Wed, 07 Jan 2009) | 1 line
use new sphinx modules
................
r68423 | benjamin.peterson | 2009-01-08 20:13:34 -0600 (Thu, 08 Jan 2009) | 29 lines
Merged revisions 68306-68308,68340,68368,68422 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r68306 | benjamin.peterson | 2009-01-04 12:27:19 -0600 (Sun, 04 Jan 2009) | 1 line
fix_urllib: add mappings for the url parsing functions
........
r68307 | benjamin.peterson | 2009-01-04 12:30:01 -0600 (Sun, 04 Jan 2009) | 1 line
remove duplicated function
........
r68308 | benjamin.peterson | 2009-01-04 12:50:34 -0600 (Sun, 04 Jan 2009) | 1 line
turtle is no longer renamed
........
r68340 | georg.brandl | 2009-01-05 02:11:39 -0600 (Mon, 05 Jan 2009) | 2 lines
Fix undefined locals in parse_tokens().
........
r68368 | benjamin.peterson | 2009-01-06 17:56:10 -0600 (Tue, 06 Jan 2009) | 1 line
fix typo (thanks to Robert Lehmann)
........
r68422 | benjamin.peterson | 2009-01-08 20:01:03 -0600 (Thu, 08 Jan 2009) | 1 line
run the imports fixers after fix_import, so fix_import doesn't try to make stdlib renames into relative imports #4876
........
................
2009-01-08 23:03:23 -04:00
|
|
|
single: trunc() (in module math)
|
2007-08-15 11:28:22 -03:00
|
|
|
pair: numeric; conversions
|
|
|
|
pair: C; language
|
|
|
|
|
2007-11-29 13:24:34 -04:00
|
|
|
Conversion from floating point to integer may round or truncate
|
2013-10-09 08:02:31 -03:00
|
|
|
as in C; see functions :func:`math.floor` and :func:`math.ceil` for
|
|
|
|
well-defined conversions.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-01-06 13:39:49 -04:00
|
|
|
(4)
|
2009-01-03 17:18:54 -04:00
|
|
|
float also accepts the strings "nan" and "inf" with an optional prefix "+"
|
Merged revisions 59541-59561 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59544 | raymond.hettinger | 2007-12-18 01:13:45 +0100 (Tue, 18 Dec 2007) | 1 line
Add more namedtuple() test cases. Neaten the code and comments.
........
r59545 | christian.heimes | 2007-12-18 04:38:03 +0100 (Tue, 18 Dec 2007) | 3 lines
Fixed for #1601: IDLE not working correctly on Windows (Py30a2/IDLE30a1)
Amaury's ideas works great. Should we build the Python core with WINVER=0x0500 and _WIN32_WINNT=0x0500, too?
........
r59546 | christian.heimes | 2007-12-18 10:00:13 +0100 (Tue, 18 Dec 2007) | 1 line
Make it a bit easier to test Tcl/Tk and idle from a build dir.
........
r59547 | christian.heimes | 2007-12-18 10:12:10 +0100 (Tue, 18 Dec 2007) | 1 line
Removed several unused files from the PCbuild9 directory. They are relics from the past.
........
r59548 | raymond.hettinger | 2007-12-18 19:26:18 +0100 (Tue, 18 Dec 2007) | 29 lines
Speed-up dictionary constructor by about 10%.
New opcode, STORE_MAP saves the compiler from awkward stack manipulations
and specializes for dicts using PyDict_SetItem instead of PyObject_SetItem.
Old disassembly:
0 BUILD_MAP 0
3 DUP_TOP
4 LOAD_CONST 1 (1)
7 ROT_TWO
8 LOAD_CONST 2 ('x')
11 STORE_SUBSCR
12 DUP_TOP
13 LOAD_CONST 3 (2)
16 ROT_TWO
17 LOAD_CONST 4 ('y')
20 STORE_SUBSCR
New disassembly:
0 BUILD_MAP 0
3 LOAD_CONST 1 (1)
6 LOAD_CONST 2 ('x')
9 STORE_MAP
10 LOAD_CONST 3 (2)
13 LOAD_CONST 4 ('y')
16 STORE_MAP
........
r59549 | thomas.heller | 2007-12-18 20:00:34 +0100 (Tue, 18 Dec 2007) | 2 lines
Issue #1642: Fix segfault in ctypes when trying to delete attributes.
........
r59551 | guido.van.rossum | 2007-12-18 21:10:42 +0100 (Tue, 18 Dec 2007) | 2 lines
Issue #1645 by Alberto Bertogli. Fix a comment.
........
r59553 | raymond.hettinger | 2007-12-18 22:24:09 +0100 (Tue, 18 Dec 2007) | 12 lines
Give meaning to the oparg for BUILD_MAP: estimated size of the dictionary.
Allows dictionaries to be pre-sized (upto 255 elements) saving time lost
to re-sizes with their attendant mallocs and re-insertions.
Has zero effect on small dictionaries (5 elements or fewer), a slight
benefit for dicts upto 22 elements (because they had to resize once
anyway), and more benefit for dicts upto 255 elements (saving multiple
resizes during the build-up and reducing the number of collisions on
the first insertions). Beyond 255 elements, there is no addional benefit.
........
r59554 | christian.heimes | 2007-12-18 22:56:09 +0100 (Tue, 18 Dec 2007) | 1 line
Fixed #1649: IDLE error: dictionary changed size during iteration
........
r59557 | raymond.hettinger | 2007-12-18 23:21:27 +0100 (Tue, 18 Dec 2007) | 1 line
Simplify and speedup _asdict() for named tuples.
........
r59558 | christian.heimes | 2007-12-19 00:22:54 +0100 (Wed, 19 Dec 2007) | 3 lines
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
The patch unifies float("inf") and repr(float("inf")) on all platforms.
........
r59559 | raymond.hettinger | 2007-12-19 00:51:15 +0100 (Wed, 19 Dec 2007) | 1 line
Users demand iterable input for named tuples. The author capitulates.
........
r59560 | raymond.hettinger | 2007-12-19 01:21:06 +0100 (Wed, 19 Dec 2007) | 1 line
Beef-up tests for dict literals
........
r59561 | raymond.hettinger | 2007-12-19 01:27:21 +0100 (Wed, 19 Dec 2007) | 1 line
Zap a duplicate line
........
2007-12-18 22:07:34 -04:00
|
|
|
or "-" for Not a Number (NaN) and positive or negative infinity.
|
Merged revisions 59774-59783 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59774 | georg.brandl | 2008-01-06 16:41:50 +0100 (Sun, 06 Jan 2008) | 2 lines
#1501: document that 0**0 == 1.
........
r59775 | georg.brandl | 2008-01-06 16:48:20 +0100 (Sun, 06 Jan 2008) | 2 lines
#759525: document that dir() doesn't return metaclass attrs when given a class as arg.
........
r59776 | georg.brandl | 2008-01-06 16:55:26 +0100 (Sun, 06 Jan 2008) | 2 lines
#1615275: clarify return object types of different tempfile factories.
........
r59777 | georg.brandl | 2008-01-06 17:01:26 +0100 (Sun, 06 Jan 2008) | 2 lines
#1727024: document that Popen.returncode is set by Popen.poll/wait.
........
r59778 | georg.brandl | 2008-01-06 17:04:56 +0100 (Sun, 06 Jan 2008) | 2 lines
#1686390: add example for csv.Sniffer use.
........
r59779 | georg.brandl | 2008-01-06 17:12:39 +0100 (Sun, 06 Jan 2008) | 2 lines
#1559684: document that shutil.copy* doesn't copy all metadata on Posix and Windows too.
........
r59780 | georg.brandl | 2008-01-06 17:17:56 +0100 (Sun, 06 Jan 2008) | 2 lines
#1582: document __reversed__, patch by Mark Russell.
........
r59781 | georg.brandl | 2008-01-06 17:22:56 +0100 (Sun, 06 Jan 2008) | 2 lines
#1499: Document compile() exceptions.
........
r59782 | georg.brandl | 2008-01-06 17:49:50 +0100 (Sun, 06 Jan 2008) | 2 lines
#1325: Add docs and tests for zipimporter.archive and zipimporter.prefix.
........
2008-01-06 13:05:40 -04:00
|
|
|
|
2008-01-06 13:39:49 -04:00
|
|
|
(5)
|
Merged revisions 59774-59783 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59774 | georg.brandl | 2008-01-06 16:41:50 +0100 (Sun, 06 Jan 2008) | 2 lines
#1501: document that 0**0 == 1.
........
r59775 | georg.brandl | 2008-01-06 16:48:20 +0100 (Sun, 06 Jan 2008) | 2 lines
#759525: document that dir() doesn't return metaclass attrs when given a class as arg.
........
r59776 | georg.brandl | 2008-01-06 16:55:26 +0100 (Sun, 06 Jan 2008) | 2 lines
#1615275: clarify return object types of different tempfile factories.
........
r59777 | georg.brandl | 2008-01-06 17:01:26 +0100 (Sun, 06 Jan 2008) | 2 lines
#1727024: document that Popen.returncode is set by Popen.poll/wait.
........
r59778 | georg.brandl | 2008-01-06 17:04:56 +0100 (Sun, 06 Jan 2008) | 2 lines
#1686390: add example for csv.Sniffer use.
........
r59779 | georg.brandl | 2008-01-06 17:12:39 +0100 (Sun, 06 Jan 2008) | 2 lines
#1559684: document that shutil.copy* doesn't copy all metadata on Posix and Windows too.
........
r59780 | georg.brandl | 2008-01-06 17:17:56 +0100 (Sun, 06 Jan 2008) | 2 lines
#1582: document __reversed__, patch by Mark Russell.
........
r59781 | georg.brandl | 2008-01-06 17:22:56 +0100 (Sun, 06 Jan 2008) | 2 lines
#1499: Document compile() exceptions.
........
r59782 | georg.brandl | 2008-01-06 17:49:50 +0100 (Sun, 06 Jan 2008) | 2 lines
#1325: Add docs and tests for zipimporter.archive and zipimporter.prefix.
........
2008-01-06 13:05:40 -04:00
|
|
|
Python defines ``pow(0, 0)`` and ``0 ** 0`` to be ``1``, as is common for
|
|
|
|
programming languages.
|
|
|
|
|
2011-03-22 21:33:17 -03:00
|
|
|
(6)
|
|
|
|
The numeric literals accepted include the digits ``0`` to ``9`` or any
|
|
|
|
Unicode equivalent (code points with the ``Nd`` property).
|
|
|
|
|
2017-06-23 03:11:52 -03:00
|
|
|
See http://www.unicode.org/Public/9.0.0/ucd/extracted/DerivedNumericType.txt
|
2011-03-22 21:33:17 -03:00
|
|
|
for a complete list of code points with the ``Nd`` property.
|
2009-01-03 17:18:54 -04:00
|
|
|
|
Merged revisions 59605-59624 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59606 | georg.brandl | 2007-12-29 11:57:00 +0100 (Sat, 29 Dec 2007) | 2 lines
Some cleanup in the docs.
........
r59611 | martin.v.loewis | 2007-12-29 19:49:21 +0100 (Sat, 29 Dec 2007) | 2 lines
Bug #1699: Define _BSD_SOURCE only on OpenBSD.
........
r59612 | raymond.hettinger | 2007-12-29 23:09:34 +0100 (Sat, 29 Dec 2007) | 1 line
Simpler documentation for itertools.tee(). Should be backported.
........
r59613 | raymond.hettinger | 2007-12-29 23:16:24 +0100 (Sat, 29 Dec 2007) | 1 line
Improve docs for itertools.groupby(). The use of xrange(0) to create a unique object is less obvious than object().
........
r59620 | christian.heimes | 2007-12-31 15:47:07 +0100 (Mon, 31 Dec 2007) | 3 lines
Added wininst-9.0.exe executable for VS 2008
Integrated bdist_wininst into PCBuild9 directory
........
r59621 | christian.heimes | 2007-12-31 15:51:18 +0100 (Mon, 31 Dec 2007) | 1 line
Moved PCbuild directory to PC/VS7.1
........
r59622 | christian.heimes | 2007-12-31 15:59:26 +0100 (Mon, 31 Dec 2007) | 1 line
Fix paths for build bot
........
r59623 | christian.heimes | 2007-12-31 16:02:41 +0100 (Mon, 31 Dec 2007) | 1 line
Fix paths for build bot, part 2
........
r59624 | christian.heimes | 2007-12-31 16:18:55 +0100 (Mon, 31 Dec 2007) | 1 line
Renamed PCBuild9 directory to PCBuild
........
2007-12-31 12:14:33 -04:00
|
|
|
|
2011-05-01 19:38:17 -03:00
|
|
|
All :class:`numbers.Real` types (:class:`int` and :class:`float`) also include
|
|
|
|
the following operations:
|
Merged revisions 59703-59773 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59704 | christian.heimes | 2008-01-04 04:15:05 +0100 (Fri, 04 Jan 2008) | 1 line
Moved include "Python.h" in front of other imports to silence a warning.
........
r59706 | raymond.hettinger | 2008-01-04 04:22:53 +0100 (Fri, 04 Jan 2008) | 10 lines
Minor fix-ups to named tuples:
* Make the _replace() method respect subclassing.
* Using property() to make _fields read-only wasn't a good idea.
It caused len(Point._fields) to fail.
* Add note to _cast() about length checking and alternative with the star-operator.
........
r59707 | jeffrey.yasskin | 2008-01-04 09:01:23 +0100 (Fri, 04 Jan 2008) | 3 lines
Make math.{floor,ceil}({int,long}) return float again for backwards
compatibility after r59671 made them return integral types.
........
r59709 | christian.heimes | 2008-01-04 14:21:07 +0100 (Fri, 04 Jan 2008) | 1 line
Bug #1713: posixpath.ismount() claims symlink to a mountpoint is a mountpoint.
........
r59712 | lars.gustaebel | 2008-01-04 15:00:33 +0100 (Fri, 04 Jan 2008) | 5 lines
Issue #1735: TarFile.extractall() now correctly sets
directory permissions and times.
(will backport to 2.5)
........
r59714 | andrew.kuchling | 2008-01-04 15:47:17 +0100 (Fri, 04 Jan 2008) | 1 line
Update links to bug/patch tracker
........
r59716 | christian.heimes | 2008-01-04 16:23:30 +0100 (Fri, 04 Jan 2008) | 1 line
Added interface to Windows' WSAIoctl and a simple example for a network sniffer.
........
r59717 | christian.heimes | 2008-01-04 16:29:00 +0100 (Fri, 04 Jan 2008) | 1 line
And here is the rest of Hirokazu Yamamoto's patch for VS6.0 support. Thanks Hiro!
........
r59719 | christian.heimes | 2008-01-04 16:34:06 +0100 (Fri, 04 Jan 2008) | 1 line
Reverted last transaction. It's the wrong branch.
........
r59721 | christian.heimes | 2008-01-04 16:48:06 +0100 (Fri, 04 Jan 2008) | 1 line
socket.ioctl is only available on Windows
........
r59722 | andrew.kuchling | 2008-01-04 19:24:41 +0100 (Fri, 04 Jan 2008) | 1 line
Fix markup
........
r59723 | andrew.kuchling | 2008-01-04 19:25:05 +0100 (Fri, 04 Jan 2008) | 1 line
Fix markup
........
r59725 | guido.van.rossum | 2008-01-05 01:59:59 +0100 (Sat, 05 Jan 2008) | 3 lines
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
and adds errors for -0x.
........
r59726 | guido.van.rossum | 2008-01-05 02:21:57 +0100 (Sat, 05 Jan 2008) | 2 lines
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
........
r59727 | raymond.hettinger | 2008-01-05 02:35:43 +0100 (Sat, 05 Jan 2008) | 1 line
Improve namedtuple's _cast() method with a docstring, new name, and error-checking.
........
r59728 | raymond.hettinger | 2008-01-05 03:17:24 +0100 (Sat, 05 Jan 2008) | 1 line
Add error-checking to namedtuple's _replace() method.
........
r59730 | fred.drake | 2008-01-05 05:38:38 +0100 (Sat, 05 Jan 2008) | 2 lines
clean up a comment
........
r59731 | jeffrey.yasskin | 2008-01-05 09:47:13 +0100 (Sat, 05 Jan 2008) | 11 lines
Continue rolling back pep-3141 changes that changed behavior from 2.5. This
round included:
* Revert round to its 2.6 behavior (half away from 0).
* Because round, floor, and ceil always return float again, it's no
longer necessary to have them delegate to __xxx___, so I've ripped
that out of their implementations and the Real ABC. This also helps
in implementing types that work in both 2.6 and 3.0: you return int
from the __xxx__ methods, and let it get enabled by the version
upgrade.
* Make pow(-1, .5) raise a ValueError again.
........
r59736 | andrew.kuchling | 2008-01-05 16:13:49 +0100 (Sat, 05 Jan 2008) | 1 line
Fix comment typo
........
r59738 | thomas.heller | 2008-01-05 18:15:44 +0100 (Sat, 05 Jan 2008) | 1 line
Add myself.
........
r59739 | georg.brandl | 2008-01-05 18:49:17 +0100 (Sat, 05 Jan 2008) | 2 lines
Fix C++-style comment.
........
r59742 | georg.brandl | 2008-01-05 20:28:16 +0100 (Sat, 05 Jan 2008) | 2 lines
Remove with_statement future imports from 2.6 docs.
........
r59743 | georg.brandl | 2008-01-05 20:29:45 +0100 (Sat, 05 Jan 2008) | 2 lines
Simplify index entries; fix #1712.
........
r59744 | georg.brandl | 2008-01-05 20:44:22 +0100 (Sat, 05 Jan 2008) | 2 lines
Doc patch #1730 from Robin Stocker; minor corrections mostly to os.rst.
........
r59749 | georg.brandl | 2008-01-05 21:29:13 +0100 (Sat, 05 Jan 2008) | 2 lines
Revert socket.rst to unix-eol.
........
r59750 | georg.brandl | 2008-01-05 21:33:46 +0100 (Sat, 05 Jan 2008) | 2 lines
Set native svn:eol-style property for text files.
........
r59752 | georg.brandl | 2008-01-05 21:46:29 +0100 (Sat, 05 Jan 2008) | 2 lines
#1719: capitalization error in "UuidCreate".
........
r59753 | georg.brandl | 2008-01-05 22:02:25 +0100 (Sat, 05 Jan 2008) | 2 lines
Repair markup.
........
r59754 | georg.brandl | 2008-01-05 22:10:50 +0100 (Sat, 05 Jan 2008) | 2 lines
Use markup.
........
r59757 | christian.heimes | 2008-01-05 22:35:52 +0100 (Sat, 05 Jan 2008) | 1 line
Final adjustments for #1601
........
r59758 | guido.van.rossum | 2008-01-05 23:19:06 +0100 (Sat, 05 Jan 2008) | 3 lines
Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
Fix by John Nagle.
........
r59759 | guido.van.rossum | 2008-01-05 23:20:01 +0100 (Sat, 05 Jan 2008) | 2 lines
Add John Nagle (of issue #1637).
........
r59765 | raymond.hettinger | 2008-01-06 10:02:24 +0100 (Sun, 06 Jan 2008) | 1 line
Small code simplification. Forgot that classmethods can be called from intances.
........
r59766 | martin.v.loewis | 2008-01-06 11:09:48 +0100 (Sun, 06 Jan 2008) | 2 lines
Use vcbuild for VS 2009.
........
r59767 | martin.v.loewis | 2008-01-06 12:03:43 +0100 (Sun, 06 Jan 2008) | 2 lines
Package using VS 2008.
........
r59768 | martin.v.loewis | 2008-01-06 12:13:16 +0100 (Sun, 06 Jan 2008) | 2 lines
Don't try to package msvcr90 for the moment.
........
r59769 | georg.brandl | 2008-01-06 15:17:36 +0100 (Sun, 06 Jan 2008) | 4 lines
#1696393: don't check for '.' and '..' in ntpath.walk since
they aren't returned from os.listdir anymore.
Reported by Michael Haggerty.
........
r59770 | georg.brandl | 2008-01-06 15:27:15 +0100 (Sun, 06 Jan 2008) | 3 lines
#1742: don't raise exception on os.path.relpath("a", "a"), but return os.curdir.
Reported by Jesse Towner.
........
r59771 | georg.brandl | 2008-01-06 15:33:52 +0100 (Sun, 06 Jan 2008) | 2 lines
#1591: Clarify docstring of Popen3.
........
r59772 | georg.brandl | 2008-01-06 16:30:34 +0100 (Sun, 06 Jan 2008) | 2 lines
#1680: fix context manager example function name.
........
r59773 | georg.brandl | 2008-01-06 16:34:57 +0100 (Sun, 06 Jan 2008) | 2 lines
#1755097: document default values for [].sort() and sorted().
........
2008-01-06 12:59:19 -04:00
|
|
|
|
2016-05-08 09:22:37 -03:00
|
|
|
+--------------------+---------------------------------------------+
|
|
|
|
| Operation | Result |
|
|
|
|
+====================+=============================================+
|
|
|
|
| :func:`math.trunc(\| *x* truncated to :class:`~numbers.Integral` |
|
|
|
|
| x) <math.trunc>` | |
|
|
|
|
+--------------------+---------------------------------------------+
|
|
|
|
| :func:`round(x[, | *x* rounded to *n* digits, |
|
|
|
|
| n]) <round>` | rounding half to even. If *n* is |
|
|
|
|
| | omitted, it defaults to 0. |
|
|
|
|
+--------------------+---------------------------------------------+
|
|
|
|
| :func:`math.floor(\| the greatest :class:`~numbers.Integral` |
|
|
|
|
| x) <math.floor>` | <= *x* |
|
|
|
|
+--------------------+---------------------------------------------+
|
|
|
|
| :func:`math.ceil(x)| the least :class:`~numbers.Integral` >= *x* |
|
|
|
|
| <math.ceil>` | |
|
|
|
|
+--------------------+---------------------------------------------+
|
Merged revisions 59703-59773 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59704 | christian.heimes | 2008-01-04 04:15:05 +0100 (Fri, 04 Jan 2008) | 1 line
Moved include "Python.h" in front of other imports to silence a warning.
........
r59706 | raymond.hettinger | 2008-01-04 04:22:53 +0100 (Fri, 04 Jan 2008) | 10 lines
Minor fix-ups to named tuples:
* Make the _replace() method respect subclassing.
* Using property() to make _fields read-only wasn't a good idea.
It caused len(Point._fields) to fail.
* Add note to _cast() about length checking and alternative with the star-operator.
........
r59707 | jeffrey.yasskin | 2008-01-04 09:01:23 +0100 (Fri, 04 Jan 2008) | 3 lines
Make math.{floor,ceil}({int,long}) return float again for backwards
compatibility after r59671 made them return integral types.
........
r59709 | christian.heimes | 2008-01-04 14:21:07 +0100 (Fri, 04 Jan 2008) | 1 line
Bug #1713: posixpath.ismount() claims symlink to a mountpoint is a mountpoint.
........
r59712 | lars.gustaebel | 2008-01-04 15:00:33 +0100 (Fri, 04 Jan 2008) | 5 lines
Issue #1735: TarFile.extractall() now correctly sets
directory permissions and times.
(will backport to 2.5)
........
r59714 | andrew.kuchling | 2008-01-04 15:47:17 +0100 (Fri, 04 Jan 2008) | 1 line
Update links to bug/patch tracker
........
r59716 | christian.heimes | 2008-01-04 16:23:30 +0100 (Fri, 04 Jan 2008) | 1 line
Added interface to Windows' WSAIoctl and a simple example for a network sniffer.
........
r59717 | christian.heimes | 2008-01-04 16:29:00 +0100 (Fri, 04 Jan 2008) | 1 line
And here is the rest of Hirokazu Yamamoto's patch for VS6.0 support. Thanks Hiro!
........
r59719 | christian.heimes | 2008-01-04 16:34:06 +0100 (Fri, 04 Jan 2008) | 1 line
Reverted last transaction. It's the wrong branch.
........
r59721 | christian.heimes | 2008-01-04 16:48:06 +0100 (Fri, 04 Jan 2008) | 1 line
socket.ioctl is only available on Windows
........
r59722 | andrew.kuchling | 2008-01-04 19:24:41 +0100 (Fri, 04 Jan 2008) | 1 line
Fix markup
........
r59723 | andrew.kuchling | 2008-01-04 19:25:05 +0100 (Fri, 04 Jan 2008) | 1 line
Fix markup
........
r59725 | guido.van.rossum | 2008-01-05 01:59:59 +0100 (Sat, 05 Jan 2008) | 3 lines
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
and adds errors for -0x.
........
r59726 | guido.van.rossum | 2008-01-05 02:21:57 +0100 (Sat, 05 Jan 2008) | 2 lines
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
........
r59727 | raymond.hettinger | 2008-01-05 02:35:43 +0100 (Sat, 05 Jan 2008) | 1 line
Improve namedtuple's _cast() method with a docstring, new name, and error-checking.
........
r59728 | raymond.hettinger | 2008-01-05 03:17:24 +0100 (Sat, 05 Jan 2008) | 1 line
Add error-checking to namedtuple's _replace() method.
........
r59730 | fred.drake | 2008-01-05 05:38:38 +0100 (Sat, 05 Jan 2008) | 2 lines
clean up a comment
........
r59731 | jeffrey.yasskin | 2008-01-05 09:47:13 +0100 (Sat, 05 Jan 2008) | 11 lines
Continue rolling back pep-3141 changes that changed behavior from 2.5. This
round included:
* Revert round to its 2.6 behavior (half away from 0).
* Because round, floor, and ceil always return float again, it's no
longer necessary to have them delegate to __xxx___, so I've ripped
that out of their implementations and the Real ABC. This also helps
in implementing types that work in both 2.6 and 3.0: you return int
from the __xxx__ methods, and let it get enabled by the version
upgrade.
* Make pow(-1, .5) raise a ValueError again.
........
r59736 | andrew.kuchling | 2008-01-05 16:13:49 +0100 (Sat, 05 Jan 2008) | 1 line
Fix comment typo
........
r59738 | thomas.heller | 2008-01-05 18:15:44 +0100 (Sat, 05 Jan 2008) | 1 line
Add myself.
........
r59739 | georg.brandl | 2008-01-05 18:49:17 +0100 (Sat, 05 Jan 2008) | 2 lines
Fix C++-style comment.
........
r59742 | georg.brandl | 2008-01-05 20:28:16 +0100 (Sat, 05 Jan 2008) | 2 lines
Remove with_statement future imports from 2.6 docs.
........
r59743 | georg.brandl | 2008-01-05 20:29:45 +0100 (Sat, 05 Jan 2008) | 2 lines
Simplify index entries; fix #1712.
........
r59744 | georg.brandl | 2008-01-05 20:44:22 +0100 (Sat, 05 Jan 2008) | 2 lines
Doc patch #1730 from Robin Stocker; minor corrections mostly to os.rst.
........
r59749 | georg.brandl | 2008-01-05 21:29:13 +0100 (Sat, 05 Jan 2008) | 2 lines
Revert socket.rst to unix-eol.
........
r59750 | georg.brandl | 2008-01-05 21:33:46 +0100 (Sat, 05 Jan 2008) | 2 lines
Set native svn:eol-style property for text files.
........
r59752 | georg.brandl | 2008-01-05 21:46:29 +0100 (Sat, 05 Jan 2008) | 2 lines
#1719: capitalization error in "UuidCreate".
........
r59753 | georg.brandl | 2008-01-05 22:02:25 +0100 (Sat, 05 Jan 2008) | 2 lines
Repair markup.
........
r59754 | georg.brandl | 2008-01-05 22:10:50 +0100 (Sat, 05 Jan 2008) | 2 lines
Use markup.
........
r59757 | christian.heimes | 2008-01-05 22:35:52 +0100 (Sat, 05 Jan 2008) | 1 line
Final adjustments for #1601
........
r59758 | guido.van.rossum | 2008-01-05 23:19:06 +0100 (Sat, 05 Jan 2008) | 3 lines
Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
Fix by John Nagle.
........
r59759 | guido.van.rossum | 2008-01-05 23:20:01 +0100 (Sat, 05 Jan 2008) | 2 lines
Add John Nagle (of issue #1637).
........
r59765 | raymond.hettinger | 2008-01-06 10:02:24 +0100 (Sun, 06 Jan 2008) | 1 line
Small code simplification. Forgot that classmethods can be called from intances.
........
r59766 | martin.v.loewis | 2008-01-06 11:09:48 +0100 (Sun, 06 Jan 2008) | 2 lines
Use vcbuild for VS 2009.
........
r59767 | martin.v.loewis | 2008-01-06 12:03:43 +0100 (Sun, 06 Jan 2008) | 2 lines
Package using VS 2008.
........
r59768 | martin.v.loewis | 2008-01-06 12:13:16 +0100 (Sun, 06 Jan 2008) | 2 lines
Don't try to package msvcr90 for the moment.
........
r59769 | georg.brandl | 2008-01-06 15:17:36 +0100 (Sun, 06 Jan 2008) | 4 lines
#1696393: don't check for '.' and '..' in ntpath.walk since
they aren't returned from os.listdir anymore.
Reported by Michael Haggerty.
........
r59770 | georg.brandl | 2008-01-06 15:27:15 +0100 (Sun, 06 Jan 2008) | 3 lines
#1742: don't raise exception on os.path.relpath("a", "a"), but return os.curdir.
Reported by Jesse Towner.
........
r59771 | georg.brandl | 2008-01-06 15:33:52 +0100 (Sun, 06 Jan 2008) | 2 lines
#1591: Clarify docstring of Popen3.
........
r59772 | georg.brandl | 2008-01-06 16:30:34 +0100 (Sun, 06 Jan 2008) | 2 lines
#1680: fix context manager example function name.
........
r59773 | georg.brandl | 2008-01-06 16:34:57 +0100 (Sun, 06 Jan 2008) | 2 lines
#1755097: document default values for [].sort() and sorted().
........
2008-01-06 12:59:19 -04:00
|
|
|
|
2008-07-01 12:50:04 -03:00
|
|
|
For additional numeric operations see the :mod:`math` and :mod:`cmath`
|
|
|
|
modules.
|
|
|
|
|
Merged revisions 59605-59624 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59606 | georg.brandl | 2007-12-29 11:57:00 +0100 (Sat, 29 Dec 2007) | 2 lines
Some cleanup in the docs.
........
r59611 | martin.v.loewis | 2007-12-29 19:49:21 +0100 (Sat, 29 Dec 2007) | 2 lines
Bug #1699: Define _BSD_SOURCE only on OpenBSD.
........
r59612 | raymond.hettinger | 2007-12-29 23:09:34 +0100 (Sat, 29 Dec 2007) | 1 line
Simpler documentation for itertools.tee(). Should be backported.
........
r59613 | raymond.hettinger | 2007-12-29 23:16:24 +0100 (Sat, 29 Dec 2007) | 1 line
Improve docs for itertools.groupby(). The use of xrange(0) to create a unique object is less obvious than object().
........
r59620 | christian.heimes | 2007-12-31 15:47:07 +0100 (Mon, 31 Dec 2007) | 3 lines
Added wininst-9.0.exe executable for VS 2008
Integrated bdist_wininst into PCBuild9 directory
........
r59621 | christian.heimes | 2007-12-31 15:51:18 +0100 (Mon, 31 Dec 2007) | 1 line
Moved PCbuild directory to PC/VS7.1
........
r59622 | christian.heimes | 2007-12-31 15:59:26 +0100 (Mon, 31 Dec 2007) | 1 line
Fix paths for build bot
........
r59623 | christian.heimes | 2007-12-31 16:02:41 +0100 (Mon, 31 Dec 2007) | 1 line
Fix paths for build bot, part 2
........
r59624 | christian.heimes | 2007-12-31 16:18:55 +0100 (Mon, 31 Dec 2007) | 1 line
Renamed PCBuild9 directory to PCBuild
........
2007-12-31 12:14:33 -04:00
|
|
|
.. XXXJH exceptions: overflow (when? what operations?) zerodivision
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. _bitstring-ops:
|
|
|
|
|
2012-01-25 17:29:03 -04:00
|
|
|
Bitwise Operations on Integer Types
|
2007-08-15 11:28:22 -03:00
|
|
|
--------------------------------------
|
|
|
|
|
Merged revisions 74074,74077,74111,74188,74192-74193,74200,74252-74253,74258-74261 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74074 | georg.brandl | 2009-07-18 05:03:10 -0400 (Sat, 18 Jul 2009) | 1 line
#6513: fix example code: warning categories are classes, not instances.
........
r74077 | georg.brandl | 2009-07-18 05:43:40 -0400 (Sat, 18 Jul 2009) | 1 line
#6489: fix an ambiguity in getiterator() documentation.
........
r74111 | benjamin.peterson | 2009-07-20 09:30:10 -0400 (Mon, 20 Jul 2009) | 1 line
remove docs for deprecated -p option
........
r74188 | benjamin.peterson | 2009-07-23 10:25:31 -0400 (Thu, 23 Jul 2009) | 1 line
use bools
........
r74192 | georg.brandl | 2009-07-24 12:28:38 -0400 (Fri, 24 Jul 2009) | 1 line
Fix arg types of et#.
........
r74193 | georg.brandl | 2009-07-24 12:46:38 -0400 (Fri, 24 Jul 2009) | 1 line
Dont put "void" in signature for nullary functions.
........
r74200 | georg.brandl | 2009-07-25 09:02:15 -0400 (Sat, 25 Jul 2009) | 1 line
#6571: add index entries for more operators.
........
r74252 | georg.brandl | 2009-07-29 12:06:31 -0400 (Wed, 29 Jul 2009) | 1 line
#6593: fix link targets.
........
r74253 | georg.brandl | 2009-07-29 12:09:17 -0400 (Wed, 29 Jul 2009) | 1 line
#6591: add reference to ioctl in fcntl module for platforms other than Windows.
........
r74258 | georg.brandl | 2009-07-29 12:57:05 -0400 (Wed, 29 Jul 2009) | 1 line
Add a link to readline, and mention IPython and bpython.
........
r74259 | georg.brandl | 2009-07-29 13:07:21 -0400 (Wed, 29 Jul 2009) | 1 line
Fix some markup and small factual glitches found by M. Markert.
........
r74260 | georg.brandl | 2009-07-29 13:15:20 -0400 (Wed, 29 Jul 2009) | 1 line
Fix a few markup glitches.
........
r74261 | georg.brandl | 2009-07-29 13:50:25 -0400 (Wed, 29 Jul 2009) | 1 line
Rewrite the section about classes a bit; mostly tidbits, and a larger update to the section about "private" variables to reflect the Pythonic consensus better.
........
2009-07-29 16:54:39 -03:00
|
|
|
.. index::
|
|
|
|
triple: operations on; integer; types
|
2012-01-25 17:29:03 -04:00
|
|
|
pair: bitwise; operations
|
Merged revisions 74074,74077,74111,74188,74192-74193,74200,74252-74253,74258-74261 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74074 | georg.brandl | 2009-07-18 05:03:10 -0400 (Sat, 18 Jul 2009) | 1 line
#6513: fix example code: warning categories are classes, not instances.
........
r74077 | georg.brandl | 2009-07-18 05:43:40 -0400 (Sat, 18 Jul 2009) | 1 line
#6489: fix an ambiguity in getiterator() documentation.
........
r74111 | benjamin.peterson | 2009-07-20 09:30:10 -0400 (Mon, 20 Jul 2009) | 1 line
remove docs for deprecated -p option
........
r74188 | benjamin.peterson | 2009-07-23 10:25:31 -0400 (Thu, 23 Jul 2009) | 1 line
use bools
........
r74192 | georg.brandl | 2009-07-24 12:28:38 -0400 (Fri, 24 Jul 2009) | 1 line
Fix arg types of et#.
........
r74193 | georg.brandl | 2009-07-24 12:46:38 -0400 (Fri, 24 Jul 2009) | 1 line
Dont put "void" in signature for nullary functions.
........
r74200 | georg.brandl | 2009-07-25 09:02:15 -0400 (Sat, 25 Jul 2009) | 1 line
#6571: add index entries for more operators.
........
r74252 | georg.brandl | 2009-07-29 12:06:31 -0400 (Wed, 29 Jul 2009) | 1 line
#6593: fix link targets.
........
r74253 | georg.brandl | 2009-07-29 12:09:17 -0400 (Wed, 29 Jul 2009) | 1 line
#6591: add reference to ioctl in fcntl module for platforms other than Windows.
........
r74258 | georg.brandl | 2009-07-29 12:57:05 -0400 (Wed, 29 Jul 2009) | 1 line
Add a link to readline, and mention IPython and bpython.
........
r74259 | georg.brandl | 2009-07-29 13:07:21 -0400 (Wed, 29 Jul 2009) | 1 line
Fix some markup and small factual glitches found by M. Markert.
........
r74260 | georg.brandl | 2009-07-29 13:15:20 -0400 (Wed, 29 Jul 2009) | 1 line
Fix a few markup glitches.
........
r74261 | georg.brandl | 2009-07-29 13:50:25 -0400 (Wed, 29 Jul 2009) | 1 line
Rewrite the section about classes a bit; mostly tidbits, and a larger update to the section about "private" variables to reflect the Pythonic consensus better.
........
2009-07-29 16:54:39 -03:00
|
|
|
pair: shifting; operations
|
|
|
|
pair: masking; operations
|
2017-06-12 16:41:42 -03:00
|
|
|
operator: |
|
Merged revisions 74074,74077,74111,74188,74192-74193,74200,74252-74253,74258-74261 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74074 | georg.brandl | 2009-07-18 05:03:10 -0400 (Sat, 18 Jul 2009) | 1 line
#6513: fix example code: warning categories are classes, not instances.
........
r74077 | georg.brandl | 2009-07-18 05:43:40 -0400 (Sat, 18 Jul 2009) | 1 line
#6489: fix an ambiguity in getiterator() documentation.
........
r74111 | benjamin.peterson | 2009-07-20 09:30:10 -0400 (Mon, 20 Jul 2009) | 1 line
remove docs for deprecated -p option
........
r74188 | benjamin.peterson | 2009-07-23 10:25:31 -0400 (Thu, 23 Jul 2009) | 1 line
use bools
........
r74192 | georg.brandl | 2009-07-24 12:28:38 -0400 (Fri, 24 Jul 2009) | 1 line
Fix arg types of et#.
........
r74193 | georg.brandl | 2009-07-24 12:46:38 -0400 (Fri, 24 Jul 2009) | 1 line
Dont put "void" in signature for nullary functions.
........
r74200 | georg.brandl | 2009-07-25 09:02:15 -0400 (Sat, 25 Jul 2009) | 1 line
#6571: add index entries for more operators.
........
r74252 | georg.brandl | 2009-07-29 12:06:31 -0400 (Wed, 29 Jul 2009) | 1 line
#6593: fix link targets.
........
r74253 | georg.brandl | 2009-07-29 12:09:17 -0400 (Wed, 29 Jul 2009) | 1 line
#6591: add reference to ioctl in fcntl module for platforms other than Windows.
........
r74258 | georg.brandl | 2009-07-29 12:57:05 -0400 (Wed, 29 Jul 2009) | 1 line
Add a link to readline, and mention IPython and bpython.
........
r74259 | georg.brandl | 2009-07-29 13:07:21 -0400 (Wed, 29 Jul 2009) | 1 line
Fix some markup and small factual glitches found by M. Markert.
........
r74260 | georg.brandl | 2009-07-29 13:15:20 -0400 (Wed, 29 Jul 2009) | 1 line
Fix a few markup glitches.
........
r74261 | georg.brandl | 2009-07-29 13:50:25 -0400 (Wed, 29 Jul 2009) | 1 line
Rewrite the section about classes a bit; mostly tidbits, and a larger update to the section about "private" variables to reflect the Pythonic consensus better.
........
2009-07-29 16:54:39 -03:00
|
|
|
operator: ^
|
|
|
|
operator: &
|
|
|
|
operator: <<
|
|
|
|
operator: >>
|
2017-06-12 16:41:42 -03:00
|
|
|
operator: ~
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-01-25 17:30:18 -04:00
|
|
|
Bitwise operations only make sense for integers. Negative numbers are treated
|
2016-03-13 03:58:24 -03:00
|
|
|
as their 2's complement value (this assumes that there are enough bits so that
|
|
|
|
no overflow occurs during the operation).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
Merged revisions 59703-59773 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59704 | christian.heimes | 2008-01-04 04:15:05 +0100 (Fri, 04 Jan 2008) | 1 line
Moved include "Python.h" in front of other imports to silence a warning.
........
r59706 | raymond.hettinger | 2008-01-04 04:22:53 +0100 (Fri, 04 Jan 2008) | 10 lines
Minor fix-ups to named tuples:
* Make the _replace() method respect subclassing.
* Using property() to make _fields read-only wasn't a good idea.
It caused len(Point._fields) to fail.
* Add note to _cast() about length checking and alternative with the star-operator.
........
r59707 | jeffrey.yasskin | 2008-01-04 09:01:23 +0100 (Fri, 04 Jan 2008) | 3 lines
Make math.{floor,ceil}({int,long}) return float again for backwards
compatibility after r59671 made them return integral types.
........
r59709 | christian.heimes | 2008-01-04 14:21:07 +0100 (Fri, 04 Jan 2008) | 1 line
Bug #1713: posixpath.ismount() claims symlink to a mountpoint is a mountpoint.
........
r59712 | lars.gustaebel | 2008-01-04 15:00:33 +0100 (Fri, 04 Jan 2008) | 5 lines
Issue #1735: TarFile.extractall() now correctly sets
directory permissions and times.
(will backport to 2.5)
........
r59714 | andrew.kuchling | 2008-01-04 15:47:17 +0100 (Fri, 04 Jan 2008) | 1 line
Update links to bug/patch tracker
........
r59716 | christian.heimes | 2008-01-04 16:23:30 +0100 (Fri, 04 Jan 2008) | 1 line
Added interface to Windows' WSAIoctl and a simple example for a network sniffer.
........
r59717 | christian.heimes | 2008-01-04 16:29:00 +0100 (Fri, 04 Jan 2008) | 1 line
And here is the rest of Hirokazu Yamamoto's patch for VS6.0 support. Thanks Hiro!
........
r59719 | christian.heimes | 2008-01-04 16:34:06 +0100 (Fri, 04 Jan 2008) | 1 line
Reverted last transaction. It's the wrong branch.
........
r59721 | christian.heimes | 2008-01-04 16:48:06 +0100 (Fri, 04 Jan 2008) | 1 line
socket.ioctl is only available on Windows
........
r59722 | andrew.kuchling | 2008-01-04 19:24:41 +0100 (Fri, 04 Jan 2008) | 1 line
Fix markup
........
r59723 | andrew.kuchling | 2008-01-04 19:25:05 +0100 (Fri, 04 Jan 2008) | 1 line
Fix markup
........
r59725 | guido.van.rossum | 2008-01-05 01:59:59 +0100 (Sat, 05 Jan 2008) | 3 lines
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
and adds errors for -0x.
........
r59726 | guido.van.rossum | 2008-01-05 02:21:57 +0100 (Sat, 05 Jan 2008) | 2 lines
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
........
r59727 | raymond.hettinger | 2008-01-05 02:35:43 +0100 (Sat, 05 Jan 2008) | 1 line
Improve namedtuple's _cast() method with a docstring, new name, and error-checking.
........
r59728 | raymond.hettinger | 2008-01-05 03:17:24 +0100 (Sat, 05 Jan 2008) | 1 line
Add error-checking to namedtuple's _replace() method.
........
r59730 | fred.drake | 2008-01-05 05:38:38 +0100 (Sat, 05 Jan 2008) | 2 lines
clean up a comment
........
r59731 | jeffrey.yasskin | 2008-01-05 09:47:13 +0100 (Sat, 05 Jan 2008) | 11 lines
Continue rolling back pep-3141 changes that changed behavior from 2.5. This
round included:
* Revert round to its 2.6 behavior (half away from 0).
* Because round, floor, and ceil always return float again, it's no
longer necessary to have them delegate to __xxx___, so I've ripped
that out of their implementations and the Real ABC. This also helps
in implementing types that work in both 2.6 and 3.0: you return int
from the __xxx__ methods, and let it get enabled by the version
upgrade.
* Make pow(-1, .5) raise a ValueError again.
........
r59736 | andrew.kuchling | 2008-01-05 16:13:49 +0100 (Sat, 05 Jan 2008) | 1 line
Fix comment typo
........
r59738 | thomas.heller | 2008-01-05 18:15:44 +0100 (Sat, 05 Jan 2008) | 1 line
Add myself.
........
r59739 | georg.brandl | 2008-01-05 18:49:17 +0100 (Sat, 05 Jan 2008) | 2 lines
Fix C++-style comment.
........
r59742 | georg.brandl | 2008-01-05 20:28:16 +0100 (Sat, 05 Jan 2008) | 2 lines
Remove with_statement future imports from 2.6 docs.
........
r59743 | georg.brandl | 2008-01-05 20:29:45 +0100 (Sat, 05 Jan 2008) | 2 lines
Simplify index entries; fix #1712.
........
r59744 | georg.brandl | 2008-01-05 20:44:22 +0100 (Sat, 05 Jan 2008) | 2 lines
Doc patch #1730 from Robin Stocker; minor corrections mostly to os.rst.
........
r59749 | georg.brandl | 2008-01-05 21:29:13 +0100 (Sat, 05 Jan 2008) | 2 lines
Revert socket.rst to unix-eol.
........
r59750 | georg.brandl | 2008-01-05 21:33:46 +0100 (Sat, 05 Jan 2008) | 2 lines
Set native svn:eol-style property for text files.
........
r59752 | georg.brandl | 2008-01-05 21:46:29 +0100 (Sat, 05 Jan 2008) | 2 lines
#1719: capitalization error in "UuidCreate".
........
r59753 | georg.brandl | 2008-01-05 22:02:25 +0100 (Sat, 05 Jan 2008) | 2 lines
Repair markup.
........
r59754 | georg.brandl | 2008-01-05 22:10:50 +0100 (Sat, 05 Jan 2008) | 2 lines
Use markup.
........
r59757 | christian.heimes | 2008-01-05 22:35:52 +0100 (Sat, 05 Jan 2008) | 1 line
Final adjustments for #1601
........
r59758 | guido.van.rossum | 2008-01-05 23:19:06 +0100 (Sat, 05 Jan 2008) | 3 lines
Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
Fix by John Nagle.
........
r59759 | guido.van.rossum | 2008-01-05 23:20:01 +0100 (Sat, 05 Jan 2008) | 2 lines
Add John Nagle (of issue #1637).
........
r59765 | raymond.hettinger | 2008-01-06 10:02:24 +0100 (Sun, 06 Jan 2008) | 1 line
Small code simplification. Forgot that classmethods can be called from intances.
........
r59766 | martin.v.loewis | 2008-01-06 11:09:48 +0100 (Sun, 06 Jan 2008) | 2 lines
Use vcbuild for VS 2009.
........
r59767 | martin.v.loewis | 2008-01-06 12:03:43 +0100 (Sun, 06 Jan 2008) | 2 lines
Package using VS 2008.
........
r59768 | martin.v.loewis | 2008-01-06 12:13:16 +0100 (Sun, 06 Jan 2008) | 2 lines
Don't try to package msvcr90 for the moment.
........
r59769 | georg.brandl | 2008-01-06 15:17:36 +0100 (Sun, 06 Jan 2008) | 4 lines
#1696393: don't check for '.' and '..' in ntpath.walk since
they aren't returned from os.listdir anymore.
Reported by Michael Haggerty.
........
r59770 | georg.brandl | 2008-01-06 15:27:15 +0100 (Sun, 06 Jan 2008) | 3 lines
#1742: don't raise exception on os.path.relpath("a", "a"), but return os.curdir.
Reported by Jesse Towner.
........
r59771 | georg.brandl | 2008-01-06 15:33:52 +0100 (Sun, 06 Jan 2008) | 2 lines
#1591: Clarify docstring of Popen3.
........
r59772 | georg.brandl | 2008-01-06 16:30:34 +0100 (Sun, 06 Jan 2008) | 2 lines
#1680: fix context manager example function name.
........
r59773 | georg.brandl | 2008-01-06 16:34:57 +0100 (Sun, 06 Jan 2008) | 2 lines
#1755097: document default values for [].sort() and sorted().
........
2008-01-06 12:59:19 -04:00
|
|
|
The priorities of the binary bitwise operations are all lower than the numeric
|
2007-08-15 11:28:22 -03:00
|
|
|
operations and higher than the comparisons; the unary operation ``~`` has the
|
|
|
|
same priority as the other unary numeric operations (``+`` and ``-``).
|
|
|
|
|
2014-10-31 05:41:46 -03:00
|
|
|
This table lists the bitwise operations sorted in ascending priority:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
+------------+--------------------------------+----------+
|
|
|
|
| Operation | Result | Notes |
|
|
|
|
+============+================================+==========+
|
|
|
|
| ``x | y`` | bitwise :dfn:`or` of *x* and | |
|
|
|
|
| | *y* | |
|
|
|
|
+------------+--------------------------------+----------+
|
|
|
|
| ``x ^ y`` | bitwise :dfn:`exclusive or` of | |
|
|
|
|
| | *x* and *y* | |
|
|
|
|
+------------+--------------------------------+----------+
|
|
|
|
| ``x & y`` | bitwise :dfn:`and` of *x* and | |
|
|
|
|
| | *y* | |
|
|
|
|
+------------+--------------------------------+----------+
|
2008-01-07 13:19:16 -04:00
|
|
|
| ``x << n`` | *x* shifted left by *n* bits | (1)(2) |
|
2007-08-15 11:28:22 -03:00
|
|
|
+------------+--------------------------------+----------+
|
2008-01-07 13:19:16 -04:00
|
|
|
| ``x >> n`` | *x* shifted right by *n* bits | (1)(3) |
|
2007-08-15 11:28:22 -03:00
|
|
|
+------------+--------------------------------+----------+
|
|
|
|
| ``~x`` | the bits of *x* inverted | |
|
|
|
|
+------------+--------------------------------+----------+
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
|
|
|
|
(1)
|
|
|
|
Negative shift counts are illegal and cause a :exc:`ValueError` to be raised.
|
|
|
|
|
|
|
|
(2)
|
|
|
|
A left shift by *n* bits is equivalent to multiplication by ``pow(2, n)``
|
|
|
|
without overflow check.
|
|
|
|
|
|
|
|
(3)
|
|
|
|
A right shift by *n* bits is equivalent to division by ``pow(2, n)`` without
|
|
|
|
overflow check.
|
|
|
|
|
|
|
|
|
2008-12-17 12:19:07 -04:00
|
|
|
Additional Methods on Integer Types
|
|
|
|
-----------------------------------
|
|
|
|
|
2011-05-01 22:14:49 -03:00
|
|
|
The int type implements the :class:`numbers.Integral` :term:`abstract base
|
2014-10-31 05:41:46 -03:00
|
|
|
class`. In addition, it provides a few more methods:
|
2011-05-01 19:38:17 -03:00
|
|
|
|
2008-12-17 12:19:07 -04:00
|
|
|
.. method:: int.bit_length()
|
|
|
|
|
2008-12-19 05:11:49 -04:00
|
|
|
Return the number of bits necessary to represent an integer in binary,
|
|
|
|
excluding the sign and leading zeros::
|
2008-12-17 12:19:07 -04:00
|
|
|
|
2008-12-19 05:11:49 -04:00
|
|
|
>>> n = -37
|
2008-12-17 12:19:07 -04:00
|
|
|
>>> bin(n)
|
2008-12-19 05:11:49 -04:00
|
|
|
'-0b100101'
|
2008-12-17 12:19:07 -04:00
|
|
|
>>> n.bit_length()
|
|
|
|
6
|
|
|
|
|
2008-12-19 05:11:49 -04:00
|
|
|
More precisely, if ``x`` is nonzero, then ``x.bit_length()`` is the
|
|
|
|
unique positive integer ``k`` such that ``2**(k-1) <= abs(x) < 2**k``.
|
|
|
|
Equivalently, when ``abs(x)`` is small enough to have a correctly
|
|
|
|
rounded logarithm, then ``k = 1 + int(log(abs(x), 2))``.
|
|
|
|
If ``x`` is zero, then ``x.bit_length()`` returns ``0``.
|
2008-12-17 12:19:07 -04:00
|
|
|
|
|
|
|
Equivalent to::
|
|
|
|
|
|
|
|
def bit_length(self):
|
2010-06-21 23:57:23 -03:00
|
|
|
s = bin(self) # binary representation: bin(-37) --> '-0b100101'
|
2008-12-19 05:11:49 -04:00
|
|
|
s = s.lstrip('-0b') # remove leading zeros and minus sign
|
|
|
|
return len(s) # len('100101') --> 6
|
2008-12-17 12:19:07 -04:00
|
|
|
|
|
|
|
.. versionadded:: 3.1
|
|
|
|
|
2010-08-17 12:07:14 -03:00
|
|
|
.. method:: int.to_bytes(length, byteorder, \*, signed=False)
|
2010-01-09 16:35:09 -04:00
|
|
|
|
|
|
|
Return an array of bytes representing an integer.
|
|
|
|
|
|
|
|
>>> (1024).to_bytes(2, byteorder='big')
|
|
|
|
b'\x04\x00'
|
|
|
|
>>> (1024).to_bytes(10, byteorder='big')
|
|
|
|
b'\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00'
|
|
|
|
>>> (-1024).to_bytes(10, byteorder='big', signed=True)
|
|
|
|
b'\xff\xff\xff\xff\xff\xff\xff\xff\xfc\x00'
|
|
|
|
>>> x = 1000
|
2016-10-31 05:41:47 -03:00
|
|
|
>>> x.to_bytes((x.bit_length() + 7) // 8, byteorder='little')
|
2010-01-09 16:35:09 -04:00
|
|
|
b'\xe8\x03'
|
|
|
|
|
|
|
|
The integer is represented using *length* bytes. An :exc:`OverflowError`
|
|
|
|
is raised if the integer is not representable with the given number of
|
|
|
|
bytes.
|
|
|
|
|
|
|
|
The *byteorder* argument determines the byte order used to represent the
|
|
|
|
integer. If *byteorder* is ``"big"``, the most significant byte is at the
|
|
|
|
beginning of the byte array. If *byteorder* is ``"little"``, the most
|
|
|
|
significant byte is at the end of the byte array. To request the native
|
|
|
|
byte order of the host system, use :data:`sys.byteorder` as the byte order
|
|
|
|
value.
|
|
|
|
|
|
|
|
The *signed* argument determines whether two's complement is used to
|
|
|
|
represent the integer. If *signed* is ``False`` and a negative integer is
|
|
|
|
given, an :exc:`OverflowError` is raised. The default value for *signed*
|
|
|
|
is ``False``.
|
|
|
|
|
|
|
|
.. versionadded:: 3.2
|
|
|
|
|
2010-08-17 12:07:14 -03:00
|
|
|
.. classmethod:: int.from_bytes(bytes, byteorder, \*, signed=False)
|
2010-01-09 16:35:09 -04:00
|
|
|
|
|
|
|
Return the integer represented by the given array of bytes.
|
|
|
|
|
|
|
|
>>> int.from_bytes(b'\x00\x10', byteorder='big')
|
|
|
|
16
|
|
|
|
>>> int.from_bytes(b'\x00\x10', byteorder='little')
|
|
|
|
4096
|
|
|
|
>>> int.from_bytes(b'\xfc\x00', byteorder='big', signed=True)
|
|
|
|
-1024
|
|
|
|
>>> int.from_bytes(b'\xfc\x00', byteorder='big', signed=False)
|
|
|
|
64512
|
|
|
|
>>> int.from_bytes([255, 0, 0], byteorder='big')
|
|
|
|
16711680
|
|
|
|
|
2013-05-04 12:06:34 -03:00
|
|
|
The argument *bytes* must either be a :term:`bytes-like object` or an
|
|
|
|
iterable producing bytes.
|
2010-01-09 16:35:09 -04:00
|
|
|
|
|
|
|
The *byteorder* argument determines the byte order used to represent the
|
|
|
|
integer. If *byteorder* is ``"big"``, the most significant byte is at the
|
|
|
|
beginning of the byte array. If *byteorder* is ``"little"``, the most
|
|
|
|
significant byte is at the end of the byte array. To request the native
|
|
|
|
byte order of the host system, use :data:`sys.byteorder` as the byte order
|
|
|
|
value.
|
|
|
|
|
|
|
|
The *signed* argument indicates whether two's complement is used to
|
|
|
|
represent the integer.
|
|
|
|
|
|
|
|
.. versionadded:: 3.2
|
|
|
|
|
2008-12-17 12:19:07 -04:00
|
|
|
|
2008-07-16 08:30:51 -03:00
|
|
|
Additional Methods on Float
|
|
|
|
---------------------------
|
|
|
|
|
2011-05-01 19:38:17 -03:00
|
|
|
The float type implements the :class:`numbers.Real` :term:`abstract base
|
|
|
|
class`. float also has the following additional methods.
|
Merged revisions 66394,66404,66412,66414,66424-66436 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r66394 | benjamin.peterson | 2008-09-11 17:04:02 -0500 (Thu, 11 Sep 2008) | 1 line
fix typo
........
r66404 | gerhard.haering | 2008-09-12 08:54:06 -0500 (Fri, 12 Sep 2008) | 2 lines
sqlite3 module: Mark iterdump() method as "Non-standard" like all the other methods not found in DB-API.
........
r66412 | gerhard.haering | 2008-09-12 13:58:57 -0500 (Fri, 12 Sep 2008) | 2 lines
Fixes issue #3103. In the sqlite3 module, made one more function static. All renaming public symbos now have the pysqlite prefix to avoid name clashes. This at least once created problems where the same symbol name appeared somewhere in Apache and the sqlite3 module was used from mod_python.
........
r66414 | gerhard.haering | 2008-09-12 17:33:22 -0500 (Fri, 12 Sep 2008) | 2 lines
Issue #3846: Release GIL during calls to sqlite3_prepare. This improves concurrent access to the same database file from multiple threads/processes.
........
r66424 | andrew.kuchling | 2008-09-12 20:22:08 -0500 (Fri, 12 Sep 2008) | 1 line
#687648 from Robert Schuppenies: use classic division. (RM Barry gave permission to update the demos.)
........
r66425 | andrew.kuchling | 2008-09-12 20:27:33 -0500 (Fri, 12 Sep 2008) | 1 line
#687648 from Robert Schuppenies: use classic division. From me: don't use string exception; flush stdout after printing
........
r66426 | andrew.kuchling | 2008-09-12 20:34:41 -0500 (Fri, 12 Sep 2008) | 1 line
#687648 from Robert Schuppenies: use classic division. From me: don't use string exception; add __main__ section
........
r66427 | andrew.kuchling | 2008-09-12 20:42:55 -0500 (Fri, 12 Sep 2008) | 1 line
#687648 from Robert Schuppenies: use classic division. From me: remove two stray semicolons
........
r66428 | andrew.kuchling | 2008-09-12 20:43:28 -0500 (Fri, 12 Sep 2008) | 1 line
#687648 from Robert Schuppenies: use classic division.
........
r66429 | andrew.kuchling | 2008-09-12 20:47:02 -0500 (Fri, 12 Sep 2008) | 1 line
Remove semicolon
........
r66430 | andrew.kuchling | 2008-09-12 20:48:36 -0500 (Fri, 12 Sep 2008) | 1 line
Subclass exception
........
r66431 | andrew.kuchling | 2008-09-12 20:56:56 -0500 (Fri, 12 Sep 2008) | 1 line
Fix SyntaxError
........
r66432 | andrew.kuchling | 2008-09-12 20:57:25 -0500 (Fri, 12 Sep 2008) | 1 line
Update uses of string exceptions
........
r66433 | andrew.kuchling | 2008-09-12 21:08:30 -0500 (Fri, 12 Sep 2008) | 1 line
Use title case
........
r66434 | andrew.kuchling | 2008-09-12 21:09:15 -0500 (Fri, 12 Sep 2008) | 1 line
Remove extra 'the'; the following title includes it
........
r66435 | andrew.kuchling | 2008-09-12 21:11:51 -0500 (Fri, 12 Sep 2008) | 1 line
#3288: Document as_integer_ratio
........
r66436 | andrew.kuchling | 2008-09-12 21:14:15 -0500 (Fri, 12 Sep 2008) | 1 line
Use title case
........
2008-09-13 12:58:53 -03:00
|
|
|
|
|
|
|
.. method:: float.as_integer_ratio()
|
|
|
|
|
2010-11-07 08:48:18 -04:00
|
|
|
Return a pair of integers whose ratio is exactly equal to the
|
|
|
|
original float and with a positive denominator. Raises
|
|
|
|
:exc:`OverflowError` on infinities and a :exc:`ValueError` on
|
|
|
|
NaNs.
|
|
|
|
|
|
|
|
.. method:: float.is_integer()
|
|
|
|
|
|
|
|
Return ``True`` if the float instance is finite with integral
|
|
|
|
value, and ``False`` otherwise::
|
|
|
|
|
|
|
|
>>> (-2.0).is_integer()
|
|
|
|
True
|
|
|
|
>>> (3.2).is_integer()
|
|
|
|
False
|
2009-01-03 17:18:54 -04:00
|
|
|
|
Merged revisions 66394,66404,66412,66414,66424-66436 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r66394 | benjamin.peterson | 2008-09-11 17:04:02 -0500 (Thu, 11 Sep 2008) | 1 line
fix typo
........
r66404 | gerhard.haering | 2008-09-12 08:54:06 -0500 (Fri, 12 Sep 2008) | 2 lines
sqlite3 module: Mark iterdump() method as "Non-standard" like all the other methods not found in DB-API.
........
r66412 | gerhard.haering | 2008-09-12 13:58:57 -0500 (Fri, 12 Sep 2008) | 2 lines
Fixes issue #3103. In the sqlite3 module, made one more function static. All renaming public symbos now have the pysqlite prefix to avoid name clashes. This at least once created problems where the same symbol name appeared somewhere in Apache and the sqlite3 module was used from mod_python.
........
r66414 | gerhard.haering | 2008-09-12 17:33:22 -0500 (Fri, 12 Sep 2008) | 2 lines
Issue #3846: Release GIL during calls to sqlite3_prepare. This improves concurrent access to the same database file from multiple threads/processes.
........
r66424 | andrew.kuchling | 2008-09-12 20:22:08 -0500 (Fri, 12 Sep 2008) | 1 line
#687648 from Robert Schuppenies: use classic division. (RM Barry gave permission to update the demos.)
........
r66425 | andrew.kuchling | 2008-09-12 20:27:33 -0500 (Fri, 12 Sep 2008) | 1 line
#687648 from Robert Schuppenies: use classic division. From me: don't use string exception; flush stdout after printing
........
r66426 | andrew.kuchling | 2008-09-12 20:34:41 -0500 (Fri, 12 Sep 2008) | 1 line
#687648 from Robert Schuppenies: use classic division. From me: don't use string exception; add __main__ section
........
r66427 | andrew.kuchling | 2008-09-12 20:42:55 -0500 (Fri, 12 Sep 2008) | 1 line
#687648 from Robert Schuppenies: use classic division. From me: remove two stray semicolons
........
r66428 | andrew.kuchling | 2008-09-12 20:43:28 -0500 (Fri, 12 Sep 2008) | 1 line
#687648 from Robert Schuppenies: use classic division.
........
r66429 | andrew.kuchling | 2008-09-12 20:47:02 -0500 (Fri, 12 Sep 2008) | 1 line
Remove semicolon
........
r66430 | andrew.kuchling | 2008-09-12 20:48:36 -0500 (Fri, 12 Sep 2008) | 1 line
Subclass exception
........
r66431 | andrew.kuchling | 2008-09-12 20:56:56 -0500 (Fri, 12 Sep 2008) | 1 line
Fix SyntaxError
........
r66432 | andrew.kuchling | 2008-09-12 20:57:25 -0500 (Fri, 12 Sep 2008) | 1 line
Update uses of string exceptions
........
r66433 | andrew.kuchling | 2008-09-12 21:08:30 -0500 (Fri, 12 Sep 2008) | 1 line
Use title case
........
r66434 | andrew.kuchling | 2008-09-12 21:09:15 -0500 (Fri, 12 Sep 2008) | 1 line
Remove extra 'the'; the following title includes it
........
r66435 | andrew.kuchling | 2008-09-12 21:11:51 -0500 (Fri, 12 Sep 2008) | 1 line
#3288: Document as_integer_ratio
........
r66436 | andrew.kuchling | 2008-09-12 21:14:15 -0500 (Fri, 12 Sep 2008) | 1 line
Use title case
........
2008-09-13 12:58:53 -03:00
|
|
|
Two methods support conversion to
|
2008-07-16 08:30:51 -03:00
|
|
|
and from hexadecimal strings. Since Python's floats are stored
|
|
|
|
internally as binary numbers, converting a float to or from a
|
|
|
|
*decimal* string usually involves a small rounding error. In
|
|
|
|
contrast, hexadecimal strings allow exact representation and
|
|
|
|
specification of floating-point numbers. This can be useful when
|
|
|
|
debugging, and in numerical work.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: float.hex()
|
|
|
|
|
|
|
|
Return a representation of a floating-point number as a hexadecimal
|
|
|
|
string. For finite floating-point numbers, this representation
|
|
|
|
will always include a leading ``0x`` and a trailing ``p`` and
|
|
|
|
exponent.
|
|
|
|
|
|
|
|
|
2009-04-12 12:51:51 -03:00
|
|
|
.. classmethod:: float.fromhex(s)
|
2008-07-16 08:30:51 -03:00
|
|
|
|
|
|
|
Class method to return the float represented by a hexadecimal
|
|
|
|
string *s*. The string *s* may have leading and trailing
|
|
|
|
whitespace.
|
|
|
|
|
|
|
|
|
|
|
|
Note that :meth:`float.hex` is an instance method, while
|
|
|
|
:meth:`float.fromhex` is a class method.
|
|
|
|
|
|
|
|
A hexadecimal string takes the form::
|
|
|
|
|
|
|
|
[sign] ['0x'] integer ['.' fraction] ['p' exponent]
|
|
|
|
|
|
|
|
where the optional ``sign`` may by either ``+`` or ``-``, ``integer``
|
|
|
|
and ``fraction`` are strings of hexadecimal digits, and ``exponent``
|
|
|
|
is a decimal integer with an optional leading sign. Case is not
|
|
|
|
significant, and there must be at least one hexadecimal digit in
|
|
|
|
either the integer or the fraction. This syntax is similar to the
|
|
|
|
syntax specified in section 6.4.4.2 of the C99 standard, and also to
|
|
|
|
the syntax used in Java 1.5 onwards. In particular, the output of
|
|
|
|
:meth:`float.hex` is usable as a hexadecimal floating-point literal in
|
|
|
|
C or Java code, and hexadecimal strings produced by C's ``%a`` format
|
|
|
|
character or Java's ``Double.toHexString`` are accepted by
|
|
|
|
:meth:`float.fromhex`.
|
|
|
|
|
|
|
|
|
|
|
|
Note that the exponent is written in decimal rather than hexadecimal,
|
|
|
|
and that it gives the power of 2 by which to multiply the coefficient.
|
|
|
|
For example, the hexadecimal string ``0x3.a7p10`` represents the
|
|
|
|
floating-point number ``(3 + 10./16 + 7./16**2) * 2.0**10``, or
|
|
|
|
``3740.0``::
|
|
|
|
|
|
|
|
>>> float.fromhex('0x3.a7p10')
|
|
|
|
3740.0
|
|
|
|
|
|
|
|
|
|
|
|
Applying the reverse conversion to ``3740.0`` gives a different
|
|
|
|
hexadecimal string representing the same number::
|
|
|
|
|
|
|
|
>>> float.hex(3740.0)
|
|
|
|
'0x1.d380000000000p+11'
|
|
|
|
|
|
|
|
|
2010-05-23 10:33:13 -03:00
|
|
|
.. _numeric-hash:
|
|
|
|
|
|
|
|
Hashing of numeric types
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
For numbers ``x`` and ``y``, possibly of different types, it's a requirement
|
|
|
|
that ``hash(x) == hash(y)`` whenever ``x == y`` (see the :meth:`__hash__`
|
|
|
|
method documentation for more details). For ease of implementation and
|
|
|
|
efficiency across a variety of numeric types (including :class:`int`,
|
|
|
|
:class:`float`, :class:`decimal.Decimal` and :class:`fractions.Fraction`)
|
|
|
|
Python's hash for numeric types is based on a single mathematical function
|
|
|
|
that's defined for any rational number, and hence applies to all instances of
|
2013-10-09 08:02:31 -03:00
|
|
|
:class:`int` and :class:`fractions.Fraction`, and all finite instances of
|
2010-05-23 10:33:13 -03:00
|
|
|
:class:`float` and :class:`decimal.Decimal`. Essentially, this function is
|
|
|
|
given by reduction modulo ``P`` for a fixed prime ``P``. The value of ``P`` is
|
|
|
|
made available to Python as the :attr:`modulus` attribute of
|
|
|
|
:data:`sys.hash_info`.
|
|
|
|
|
|
|
|
.. impl-detail::
|
|
|
|
|
|
|
|
Currently, the prime used is ``P = 2**31 - 1`` on machines with 32-bit C
|
|
|
|
longs and ``P = 2**61 - 1`` on machines with 64-bit C longs.
|
|
|
|
|
|
|
|
Here are the rules in detail:
|
|
|
|
|
2012-03-24 04:12:41 -03:00
|
|
|
- If ``x = m / n`` is a nonnegative rational number and ``n`` is not divisible
|
|
|
|
by ``P``, define ``hash(x)`` as ``m * invmod(n, P) % P``, where ``invmod(n,
|
|
|
|
P)`` gives the inverse of ``n`` modulo ``P``.
|
|
|
|
|
|
|
|
- If ``x = m / n`` is a nonnegative rational number and ``n`` is
|
|
|
|
divisible by ``P`` (but ``m`` is not) then ``n`` has no inverse
|
|
|
|
modulo ``P`` and the rule above doesn't apply; in this case define
|
|
|
|
``hash(x)`` to be the constant value ``sys.hash_info.inf``.
|
|
|
|
|
|
|
|
- If ``x = m / n`` is a negative rational number define ``hash(x)``
|
|
|
|
as ``-hash(-x)``. If the resulting hash is ``-1``, replace it with
|
|
|
|
``-2``.
|
|
|
|
|
|
|
|
- The particular values ``sys.hash_info.inf``, ``-sys.hash_info.inf``
|
|
|
|
and ``sys.hash_info.nan`` are used as hash values for positive
|
|
|
|
infinity, negative infinity, or nans (respectively). (All hashable
|
|
|
|
nans have the same hash value.)
|
|
|
|
|
|
|
|
- For a :class:`complex` number ``z``, the hash values of the real
|
|
|
|
and imaginary parts are combined by computing ``hash(z.real) +
|
|
|
|
sys.hash_info.imag * hash(z.imag)``, reduced modulo
|
|
|
|
``2**sys.hash_info.width`` so that it lies in
|
|
|
|
``range(-2**(sys.hash_info.width - 1), 2**(sys.hash_info.width -
|
|
|
|
1))``. Again, if the result is ``-1``, it's replaced with ``-2``.
|
2010-05-23 10:33:13 -03:00
|
|
|
|
|
|
|
|
|
|
|
To clarify the above rules, here's some example Python code,
|
2012-08-20 04:14:07 -03:00
|
|
|
equivalent to the built-in hash, for computing the hash of a rational
|
2010-05-23 10:33:13 -03:00
|
|
|
number, :class:`float`, or :class:`complex`::
|
|
|
|
|
|
|
|
|
|
|
|
import sys, math
|
|
|
|
|
|
|
|
def hash_fraction(m, n):
|
|
|
|
"""Compute the hash of a rational number m / n.
|
|
|
|
|
|
|
|
Assumes m and n are integers, with n positive.
|
|
|
|
Equivalent to hash(fractions.Fraction(m, n)).
|
|
|
|
|
|
|
|
"""
|
|
|
|
P = sys.hash_info.modulus
|
|
|
|
# Remove common factors of P. (Unnecessary if m and n already coprime.)
|
|
|
|
while m % P == n % P == 0:
|
|
|
|
m, n = m // P, n // P
|
|
|
|
|
|
|
|
if n % P == 0:
|
2016-07-24 22:55:51 -03:00
|
|
|
hash_value = sys.hash_info.inf
|
2010-05-23 10:33:13 -03:00
|
|
|
else:
|
|
|
|
# Fermat's Little Theorem: pow(n, P-1, P) is 1, so
|
|
|
|
# pow(n, P-2, P) gives the inverse of n modulo P.
|
2016-07-24 22:55:51 -03:00
|
|
|
hash_value = (abs(m) % P) * pow(n, P - 2, P) % P
|
2010-05-23 10:33:13 -03:00
|
|
|
if m < 0:
|
2016-07-24 22:55:51 -03:00
|
|
|
hash_value = -hash_value
|
|
|
|
if hash_value == -1:
|
|
|
|
hash_value = -2
|
|
|
|
return hash_value
|
2010-05-23 10:33:13 -03:00
|
|
|
|
|
|
|
def hash_float(x):
|
|
|
|
"""Compute the hash of a float x."""
|
|
|
|
|
|
|
|
if math.isnan(x):
|
|
|
|
return sys.hash_info.nan
|
|
|
|
elif math.isinf(x):
|
|
|
|
return sys.hash_info.inf if x > 0 else -sys.hash_info.inf
|
|
|
|
else:
|
|
|
|
return hash_fraction(*x.as_integer_ratio())
|
|
|
|
|
|
|
|
def hash_complex(z):
|
|
|
|
"""Compute the hash of a complex number z."""
|
|
|
|
|
2016-07-24 22:55:51 -03:00
|
|
|
hash_value = hash_float(z.real) + sys.hash_info.imag * hash_float(z.imag)
|
2010-05-23 10:33:13 -03:00
|
|
|
# do a signed reduction modulo 2**sys.hash_info.width
|
|
|
|
M = 2**(sys.hash_info.width - 1)
|
2016-07-24 22:55:51 -03:00
|
|
|
hash_value = (hash_value & (M - 1)) - (hash_value & M)
|
|
|
|
if hash_value == -1:
|
|
|
|
hash_value = -2
|
|
|
|
return hash_value
|
2010-05-23 10:33:13 -03:00
|
|
|
|
2008-07-16 09:58:29 -03:00
|
|
|
.. _typeiter:
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
Iterator Types
|
|
|
|
==============
|
|
|
|
|
|
|
|
.. index::
|
|
|
|
single: iterator protocol
|
|
|
|
single: protocol; iterator
|
|
|
|
single: sequence; iteration
|
|
|
|
single: container; iteration over
|
|
|
|
|
|
|
|
Python supports a concept of iteration over containers. This is implemented
|
|
|
|
using two distinct methods; these are used to allow user-defined classes to
|
|
|
|
support iteration. Sequences, described below in more detail, always support
|
|
|
|
the iteration methods.
|
|
|
|
|
|
|
|
One method needs to be defined for container objects to provide iteration
|
|
|
|
support:
|
|
|
|
|
Merged revisions 59822-59841 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59822 | georg.brandl | 2008-01-07 17:43:47 +0100 (Mon, 07 Jan 2008) | 2 lines
Restore "somenamedtuple" as the "class" for named tuple attrs.
........
r59824 | georg.brandl | 2008-01-07 18:09:35 +0100 (Mon, 07 Jan 2008) | 2 lines
Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
........
r59827 | georg.brandl | 2008-01-07 18:25:53 +0100 (Mon, 07 Jan 2008) | 2 lines
patch #1668: clarify envvar docs; rename THREADDEBUG to PYTHONTHREADDEBUG.
........
r59830 | georg.brandl | 2008-01-07 19:16:36 +0100 (Mon, 07 Jan 2008) | 2 lines
Make Python compile with --disable-unicode.
........
r59831 | georg.brandl | 2008-01-07 19:23:27 +0100 (Mon, 07 Jan 2008) | 2 lines
Restructure urllib doc structure.
........
r59833 | georg.brandl | 2008-01-07 19:41:34 +0100 (Mon, 07 Jan 2008) | 2 lines
Fix #define ordering.
........
r59834 | georg.brandl | 2008-01-07 19:47:44 +0100 (Mon, 07 Jan 2008) | 2 lines
#467924, patch by Alan McIntyre: Add ZipFile.extract and ZipFile.extractall.
........
r59835 | raymond.hettinger | 2008-01-07 19:52:19 +0100 (Mon, 07 Jan 2008) | 1 line
Fix inconsistent title levels -- it made the whole doc build crash horribly.
........
r59836 | georg.brandl | 2008-01-07 19:57:03 +0100 (Mon, 07 Jan 2008) | 2 lines
Fix two further doc build warnings.
........
r59837 | georg.brandl | 2008-01-07 20:17:10 +0100 (Mon, 07 Jan 2008) | 2 lines
Clarify metaclass docs and add example.
........
r59838 | vinay.sajip | 2008-01-07 20:40:10 +0100 (Mon, 07 Jan 2008) | 1 line
Added section about adding contextual information to log output.
........
r59839 | christian.heimes | 2008-01-07 20:58:41 +0100 (Mon, 07 Jan 2008) | 1 line
Fixed indention problem that caused the second TIPC test to run on systems without TIPC
........
r59840 | raymond.hettinger | 2008-01-07 21:07:38 +0100 (Mon, 07 Jan 2008) | 1 line
Cleanup named tuple subclassing example.
........
2008-01-07 17:14:23 -04:00
|
|
|
.. XXX duplicated in reference/datamodel!
|
2007-08-15 11:28:22 -03:00
|
|
|
|
Merged revisions 59822-59841 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59822 | georg.brandl | 2008-01-07 17:43:47 +0100 (Mon, 07 Jan 2008) | 2 lines
Restore "somenamedtuple" as the "class" for named tuple attrs.
........
r59824 | georg.brandl | 2008-01-07 18:09:35 +0100 (Mon, 07 Jan 2008) | 2 lines
Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
........
r59827 | georg.brandl | 2008-01-07 18:25:53 +0100 (Mon, 07 Jan 2008) | 2 lines
patch #1668: clarify envvar docs; rename THREADDEBUG to PYTHONTHREADDEBUG.
........
r59830 | georg.brandl | 2008-01-07 19:16:36 +0100 (Mon, 07 Jan 2008) | 2 lines
Make Python compile with --disable-unicode.
........
r59831 | georg.brandl | 2008-01-07 19:23:27 +0100 (Mon, 07 Jan 2008) | 2 lines
Restructure urllib doc structure.
........
r59833 | georg.brandl | 2008-01-07 19:41:34 +0100 (Mon, 07 Jan 2008) | 2 lines
Fix #define ordering.
........
r59834 | georg.brandl | 2008-01-07 19:47:44 +0100 (Mon, 07 Jan 2008) | 2 lines
#467924, patch by Alan McIntyre: Add ZipFile.extract and ZipFile.extractall.
........
r59835 | raymond.hettinger | 2008-01-07 19:52:19 +0100 (Mon, 07 Jan 2008) | 1 line
Fix inconsistent title levels -- it made the whole doc build crash horribly.
........
r59836 | georg.brandl | 2008-01-07 19:57:03 +0100 (Mon, 07 Jan 2008) | 2 lines
Fix two further doc build warnings.
........
r59837 | georg.brandl | 2008-01-07 20:17:10 +0100 (Mon, 07 Jan 2008) | 2 lines
Clarify metaclass docs and add example.
........
r59838 | vinay.sajip | 2008-01-07 20:40:10 +0100 (Mon, 07 Jan 2008) | 1 line
Added section about adding contextual information to log output.
........
r59839 | christian.heimes | 2008-01-07 20:58:41 +0100 (Mon, 07 Jan 2008) | 1 line
Fixed indention problem that caused the second TIPC test to run on systems without TIPC
........
r59840 | raymond.hettinger | 2008-01-07 21:07:38 +0100 (Mon, 07 Jan 2008) | 1 line
Cleanup named tuple subclassing example.
........
2008-01-07 17:14:23 -04:00
|
|
|
.. method:: container.__iter__()
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Return an iterator object. The object is required to support the iterator
|
|
|
|
protocol described below. If a container supports different types of
|
|
|
|
iteration, additional methods can be provided to specifically request
|
|
|
|
iterators for those iteration types. (An example of an object supporting
|
|
|
|
multiple forms of iteration would be a tree structure which supports both
|
|
|
|
breadth-first and depth-first traversal.) This method corresponds to the
|
2013-08-01 16:12:45 -03:00
|
|
|
:c:member:`~PyTypeObject.tp_iter` slot of the type structure for Python objects in the Python/C
|
2007-08-15 11:28:22 -03:00
|
|
|
API.
|
|
|
|
|
|
|
|
The iterator objects themselves are required to support the following two
|
|
|
|
methods, which together form the :dfn:`iterator protocol`:
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: iterator.__iter__()
|
|
|
|
|
|
|
|
Return the iterator object itself. This is required to allow both containers
|
|
|
|
and iterators to be used with the :keyword:`for` and :keyword:`in` statements.
|
2013-08-01 16:12:45 -03:00
|
|
|
This method corresponds to the :c:member:`~PyTypeObject.tp_iter` slot of the type structure for
|
2007-08-15 11:28:22 -03:00
|
|
|
Python objects in the Python/C API.
|
|
|
|
|
|
|
|
|
2007-09-28 10:39:25 -03:00
|
|
|
.. method:: iterator.__next__()
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Return the next item from the container. If there are no further items, raise
|
|
|
|
the :exc:`StopIteration` exception. This method corresponds to the
|
2013-08-01 16:12:45 -03:00
|
|
|
:c:member:`~PyTypeObject.tp_iternext` slot of the type structure for Python objects in the
|
2007-08-15 11:28:22 -03:00
|
|
|
Python/C API.
|
|
|
|
|
|
|
|
Python defines several iterator objects to support iteration over general and
|
|
|
|
specific sequence types, dictionaries, and other more specialized forms. The
|
|
|
|
specific types are not important beyond their implementation of the iterator
|
|
|
|
protocol.
|
|
|
|
|
2012-10-12 07:42:08 -03:00
|
|
|
Once an iterator's :meth:`~iterator.__next__` method raises
|
|
|
|
:exc:`StopIteration`, it must continue to do so on subsequent calls.
|
|
|
|
Implementations that do not obey this property are deemed broken.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
Merged revisions 73004,73439,73496,73509,73529,73564,73576-73577,73595-73596,73605 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r73004 | jeffrey.yasskin | 2009-05-28 22:44:31 -0500 (Thu, 28 May 2009) | 5 lines
Fix nearly all compilation warnings under Apple gcc-4.0. Tested with OPT="-g
-Wall -Wstrict-prototypes -Werror" in both --with-pydebug mode and --without.
There's still a batch of non-prototype warnings in Xlib.h that I don't know how
to fix.
........
r73439 | benjamin.peterson | 2009-06-15 19:29:31 -0500 (Mon, 15 Jun 2009) | 1 line
don't mask encoding errors when decoding a string #6289
........
r73496 | vinay.sajip | 2009-06-21 12:37:27 -0500 (Sun, 21 Jun 2009) | 1 line
Issue #6314: logging.basicConfig() performs extra checks on the "level" argument.
........
r73509 | amaury.forgeotdarc | 2009-06-22 14:33:48 -0500 (Mon, 22 Jun 2009) | 2 lines
#4490 Fix sample code run by "python -m xml.sax.xmlreader"
........
r73529 | r.david.murray | 2009-06-23 13:02:46 -0500 (Tue, 23 Jun 2009) | 4 lines
Fix issue 5230 by having pydoc's safeimport check to see if the import
error was thrown from itself in order to decide if the module can't be
found. Thanks to Lucas Prado Melo for collaborating on the fix and tests.
........
r73564 | amaury.forgeotdarc | 2009-06-25 17:29:29 -0500 (Thu, 25 Jun 2009) | 6 lines
#2016 Fix a crash in function call when the **kwargs dictionary is mutated
during the function call setup.
This even gives a slight speedup, probably because tuple allocation
is faster than PyMem_NEW.
........
r73576 | benjamin.peterson | 2009-06-26 18:37:06 -0500 (Fri, 26 Jun 2009) | 1 line
document is_declared_global()
........
r73577 | benjamin.peterson | 2009-06-27 09:16:23 -0500 (Sat, 27 Jun 2009) | 1 line
link to extensive generator docs in the reference manual
........
r73595 | ezio.melotti | 2009-06-27 18:45:39 -0500 (Sat, 27 Jun 2009) | 1 line
stmt and setup can contain multiple statements, see #5896
........
r73596 | ezio.melotti | 2009-06-27 19:07:45 -0500 (Sat, 27 Jun 2009) | 1 line
Fixed a wrong apostrophe
........
r73605 | georg.brandl | 2009-06-28 07:10:18 -0500 (Sun, 28 Jun 2009) | 1 line
Remove stray pychecker directive.
........
2009-06-28 14:22:03 -03:00
|
|
|
|
|
|
|
.. _generator-types:
|
|
|
|
|
|
|
|
Generator Types
|
|
|
|
---------------
|
|
|
|
|
#1370: Finish the merge r58749, log below, by resolving all conflicts in Doc/.
Merged revisions 58221-58741 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58221 | georg.brandl | 2007-09-20 10:57:59 -0700 (Thu, 20 Sep 2007) | 2 lines
Patch #1181: add os.environ.clear() method.
........
r58225 | sean.reifschneider | 2007-09-20 23:33:28 -0700 (Thu, 20 Sep 2007) | 3 lines
Issue1704287: "make install" fails unless you do "make" first. Make
oldsharedmods and sharedmods in "libinstall".
........
r58232 | guido.van.rossum | 2007-09-22 13:18:03 -0700 (Sat, 22 Sep 2007) | 4 lines
Patch # 188 by Philip Jenvey.
Make tell() mark CRLF as a newline.
With unit test.
........
r58242 | georg.brandl | 2007-09-24 10:55:47 -0700 (Mon, 24 Sep 2007) | 2 lines
Fix typo and double word.
........
r58245 | georg.brandl | 2007-09-24 10:59:28 -0700 (Mon, 24 Sep 2007) | 2 lines
#1196: document default radix for int().
........
r58247 | georg.brandl | 2007-09-24 11:08:24 -0700 (Mon, 24 Sep 2007) | 2 lines
#1177: accept 2xx responses for https too, not only http.
........
r58249 | andrew.kuchling | 2007-09-24 16:45:51 -0700 (Mon, 24 Sep 2007) | 1 line
Remove stray odd character; grammar fix
........
r58250 | andrew.kuchling | 2007-09-24 16:46:28 -0700 (Mon, 24 Sep 2007) | 1 line
Typo fix
........
r58251 | andrew.kuchling | 2007-09-24 17:09:42 -0700 (Mon, 24 Sep 2007) | 1 line
Add various items
........
r58268 | vinay.sajip | 2007-09-26 22:34:45 -0700 (Wed, 26 Sep 2007) | 1 line
Change to flush and close logic to fix #1760556.
........
r58269 | vinay.sajip | 2007-09-26 22:38:51 -0700 (Wed, 26 Sep 2007) | 1 line
Change to basicConfig() to fix #1021.
........
r58270 | georg.brandl | 2007-09-26 23:26:58 -0700 (Wed, 26 Sep 2007) | 2 lines
#1208: document match object's boolean value.
........
r58271 | vinay.sajip | 2007-09-26 23:56:13 -0700 (Wed, 26 Sep 2007) | 1 line
Minor date change.
........
r58272 | vinay.sajip | 2007-09-27 00:35:10 -0700 (Thu, 27 Sep 2007) | 1 line
Change to LogRecord.__init__() to fix #1206. Note that archaic use of type(x) == types.DictType is because of keeping 1.5.2 compatibility. While this is much less relevant these days, there probably needs to be a separate commit for removing all archaic constructs at the same time.
........
r58288 | brett.cannon | 2007-09-30 12:45:10 -0700 (Sun, 30 Sep 2007) | 9 lines
tuple.__repr__ did not consider a reference loop as it is not possible from
Python code; but it is possible from C. object.__str__ had the issue of not
expecting a type to doing something within it's tp_str implementation that
could trigger an infinite recursion, but it could in C code.. Both found
thanks to BaseException and how it handles its repr.
Closes issue #1686386. Thanks to Thomas Herve for taking an initial stab at
coming up with a solution.
........
r58289 | brett.cannon | 2007-09-30 13:37:19 -0700 (Sun, 30 Sep 2007) | 3 lines
Fix error introduced by r58288; if a tuple is length 0 return its repr and
don't worry about any self-referring tuples.
........
r58294 | facundo.batista | 2007-10-02 10:01:24 -0700 (Tue, 02 Oct 2007) | 11 lines
Made the various is_* operations return booleans. This was discussed
with Cawlishaw by mail, and he basically confirmed that to these is_*
operations, there's no need to return Decimal(0) and Decimal(1) if
the language supports the False and True booleans.
Also added a few tests for the these functions in extra.decTest, since
they are mostly untested (apart from the doctests).
Thanks Mark Dickinson
........
r58295 | facundo.batista | 2007-10-02 11:21:18 -0700 (Tue, 02 Oct 2007) | 4 lines
Added a class to store the digits of log(10), so that they can be made
available when necessary without recomputing. Thanks Mark Dickinson
........
r58299 | mark.summerfield | 2007-10-03 01:53:21 -0700 (Wed, 03 Oct 2007) | 4 lines
Added note in footnote about string comparisons about
unicodedata.normalize().
........
r58304 | raymond.hettinger | 2007-10-03 14:18:11 -0700 (Wed, 03 Oct 2007) | 1 line
enumerate() is no longer bounded to using sequences shorter than LONG_MAX. The possibility of overflow was sending some newsgroup posters into a tizzy.
........
r58305 | raymond.hettinger | 2007-10-03 17:20:27 -0700 (Wed, 03 Oct 2007) | 1 line
itertools.count() no longer limited to sys.maxint.
........
r58306 | kurt.kaiser | 2007-10-03 18:49:54 -0700 (Wed, 03 Oct 2007) | 3 lines
Assume that the user knows when he wants to end the line; don't insert
something he didn't select or complete.
........
r58307 | kurt.kaiser | 2007-10-03 19:07:50 -0700 (Wed, 03 Oct 2007) | 2 lines
Remove unused theme that was causing a fault in p3k.
........
r58308 | kurt.kaiser | 2007-10-03 19:09:17 -0700 (Wed, 03 Oct 2007) | 2 lines
Clean up EditorWindow close.
........
r58309 | kurt.kaiser | 2007-10-03 19:53:07 -0700 (Wed, 03 Oct 2007) | 7 lines
textView cleanup. Patch 1718043 Tal Einat.
M idlelib/EditorWindow.py
M idlelib/aboutDialog.py
M idlelib/textView.py
M idlelib/NEWS.txt
........
r58310 | kurt.kaiser | 2007-10-03 20:11:12 -0700 (Wed, 03 Oct 2007) | 3 lines
configDialog cleanup. Patch 1730217 Tal Einat.
........
r58311 | neal.norwitz | 2007-10-03 23:00:48 -0700 (Wed, 03 Oct 2007) | 4 lines
Coverity #151: Remove deadcode.
All this code already exists above starting at line 653.
........
r58325 | fred.drake | 2007-10-04 19:46:12 -0700 (Thu, 04 Oct 2007) | 1 line
wrap lines to <80 characters before fixing errors
........
r58326 | raymond.hettinger | 2007-10-04 19:47:07 -0700 (Thu, 04 Oct 2007) | 6 lines
Add __asdict__() to NamedTuple and refine the docs.
Add maxlen support to deque() and fixup docs.
Partially fix __reduce__(). The None as a third arg was no longer supported.
Still needs work on __reduce__() to handle recursive inputs.
........
r58327 | fred.drake | 2007-10-04 19:48:32 -0700 (Thu, 04 Oct 2007) | 3 lines
move descriptions of ac_(in|out)_buffer_size to the right place
http://bugs.python.org/issue1053
........
r58329 | neal.norwitz | 2007-10-04 20:39:17 -0700 (Thu, 04 Oct 2007) | 3 lines
dict could be NULL, so we need to XDECREF.
Fix a compiler warning about passing a PyTypeObject* instead of PyObject*.
........
r58330 | neal.norwitz | 2007-10-04 20:41:19 -0700 (Thu, 04 Oct 2007) | 2 lines
Fix Coverity #158: Check the correct variable.
........
r58332 | neal.norwitz | 2007-10-04 22:01:38 -0700 (Thu, 04 Oct 2007) | 7 lines
Fix Coverity #159.
This code was broken if save() returned a negative number since i contained
a boolean value and then we compared i < 0 which should never be true.
Will backport (assuming it's necessary)
........
r58334 | neal.norwitz | 2007-10-04 22:29:17 -0700 (Thu, 04 Oct 2007) | 1 line
Add a note about fixing some more warnings found by Coverity.
........
r58338 | raymond.hettinger | 2007-10-05 12:07:31 -0700 (Fri, 05 Oct 2007) | 1 line
Restore BEGIN/END THREADS macros which were squashed in the previous checkin
........
r58343 | gregory.p.smith | 2007-10-06 00:48:10 -0700 (Sat, 06 Oct 2007) | 3 lines
Stab in the dark attempt to fix the test_bsddb3 failure on sparc and S-390
ubuntu buildbots.
........
r58344 | gregory.p.smith | 2007-10-06 00:51:59 -0700 (Sat, 06 Oct 2007) | 2 lines
Allows BerkeleyDB 4.6.x >= 4.6.21 for the bsddb module.
........
r58348 | gregory.p.smith | 2007-10-06 08:47:37 -0700 (Sat, 06 Oct 2007) | 3 lines
Use the host the author likely meant in the first place. pop.gmail.com is
reliable. gmail.org is someones personal domain.
........
r58351 | neal.norwitz | 2007-10-06 12:16:28 -0700 (Sat, 06 Oct 2007) | 3 lines
Ensure that this test will pass even if another test left an unwritable TESTFN.
Also use the safe unlink in test_support instead of rolling our own here.
........
r58368 | georg.brandl | 2007-10-08 00:50:24 -0700 (Mon, 08 Oct 2007) | 3 lines
#1123: fix the docs for the str.split(None, sep) case.
Also expand a few other methods' docs, which had more info in the deprecated string module docs.
........
r58369 | georg.brandl | 2007-10-08 01:06:05 -0700 (Mon, 08 Oct 2007) | 2 lines
Update docstring of sched, also remove an unused assignment.
........
r58370 | raymond.hettinger | 2007-10-08 02:14:28 -0700 (Mon, 08 Oct 2007) | 5 lines
Add comments to NamedTuple code.
Let the field spec be either a string or a non-string sequence (suggested by Martin Blais with use cases).
Improve the error message in the case of a SyntaxError (caused by a duplicate field name).
........
r58371 | raymond.hettinger | 2007-10-08 02:56:29 -0700 (Mon, 08 Oct 2007) | 1 line
Missed a line in the docs
........
r58372 | raymond.hettinger | 2007-10-08 03:11:51 -0700 (Mon, 08 Oct 2007) | 1 line
Better variable names
........
r58376 | georg.brandl | 2007-10-08 07:12:47 -0700 (Mon, 08 Oct 2007) | 3 lines
#1199: docs for tp_as_{number,sequence,mapping}, by Amaury Forgeot d'Arc.
No need to merge this to py3k!
........
r58380 | raymond.hettinger | 2007-10-08 14:26:58 -0700 (Mon, 08 Oct 2007) | 1 line
Eliminate camelcase function name
........
r58381 | andrew.kuchling | 2007-10-08 16:23:03 -0700 (Mon, 08 Oct 2007) | 1 line
Eliminate camelcase function name
........
r58382 | raymond.hettinger | 2007-10-08 18:36:23 -0700 (Mon, 08 Oct 2007) | 1 line
Make the error messages more specific
........
r58384 | gregory.p.smith | 2007-10-08 23:02:21 -0700 (Mon, 08 Oct 2007) | 10 lines
Splits Modules/_bsddb.c up into bsddb.h and _bsddb.c and adds a C API
object available as bsddb.db.api. This is based on the patch submitted
by Duncan Grisby here:
http://sourceforge.net/tracker/index.php?func=detail&aid=1551895&group_id=13900&atid=313900
See this thread for additional info:
http://sourceforge.net/mailarchive/forum.php?thread_name=E1GAVDK-0002rk-Iw%40apasphere.com&forum_name=pybsddb-users
It also cleans up the code a little by removing some ifdef/endifs for
python prior to 2.1 and for unsupported Berkeley DB <= 3.2.
........
r58385 | gregory.p.smith | 2007-10-08 23:50:43 -0700 (Mon, 08 Oct 2007) | 5 lines
Fix a double free when positioning a database cursor to a non-existant
string key (and probably a few other situations with string keys).
This was reported with a patch as pybsddb sourceforge bug 1708868 by
jjjhhhlll at gmail.
........
r58386 | gregory.p.smith | 2007-10-09 00:19:11 -0700 (Tue, 09 Oct 2007) | 3 lines
Use the highest cPickle protocol in bsddb.dbshelve. This comes from
sourceforge pybsddb patch 1551443 by w_barnes.
........
r58394 | gregory.p.smith | 2007-10-09 11:26:02 -0700 (Tue, 09 Oct 2007) | 2 lines
remove another sleepycat reference
........
r58396 | kurt.kaiser | 2007-10-09 12:31:30 -0700 (Tue, 09 Oct 2007) | 3 lines
Allow interrupt only when executing user code in subprocess
Patch 1225 Tal Einat modified from IDLE-Spoon.
........
r58399 | brett.cannon | 2007-10-09 17:07:50 -0700 (Tue, 09 Oct 2007) | 5 lines
Remove file-level typedefs that were inconsistently used throughout the file.
Just move over to the public API names.
Closes issue1238.
........
r58401 | raymond.hettinger | 2007-10-09 17:26:46 -0700 (Tue, 09 Oct 2007) | 1 line
Accept Jim Jewett's api suggestion to use None instead of -1 to indicate unbounded deques.
........
r58403 | kurt.kaiser | 2007-10-09 17:55:40 -0700 (Tue, 09 Oct 2007) | 2 lines
Allow cursor color change w/o restart. Patch 1725576 Tal Einat.
........
r58404 | kurt.kaiser | 2007-10-09 18:06:47 -0700 (Tue, 09 Oct 2007) | 2 lines
show paste if > 80 columns. Patch 1659326 Tal Einat.
........
r58415 | thomas.heller | 2007-10-11 12:51:32 -0700 (Thu, 11 Oct 2007) | 5 lines
On OS X, use os.uname() instead of gestalt.sysv(...) to get the
operating system version. This allows to use ctypes when Python
was configured with --disable-toolbox-glue.
........
r58419 | neal.norwitz | 2007-10-11 20:01:01 -0700 (Thu, 11 Oct 2007) | 1 line
Get rid of warning about not being able to create an existing directory.
........
r58420 | neal.norwitz | 2007-10-11 20:01:30 -0700 (Thu, 11 Oct 2007) | 1 line
Get rid of warnings on a bunch of platforms by using a proper prototype.
........
r58421 | neal.norwitz | 2007-10-11 20:01:54 -0700 (Thu, 11 Oct 2007) | 4 lines
Get rid of compiler warning about retval being used (returned) without
being initialized. (gcc warning and Coverity 202)
........
r58422 | neal.norwitz | 2007-10-11 20:03:23 -0700 (Thu, 11 Oct 2007) | 1 line
Fix Coverity 168: Close the file before returning (exiting).
........
r58423 | neal.norwitz | 2007-10-11 20:04:18 -0700 (Thu, 11 Oct 2007) | 4 lines
Fix Coverity 180: Don't overallocate. We don't need structs, but pointers.
Also fix a memory leak.
........
r58424 | neal.norwitz | 2007-10-11 20:05:19 -0700 (Thu, 11 Oct 2007) | 5 lines
Fix Coverity 185-186: If the passed in FILE is NULL, uninitialized memory
would be accessed.
Will backport.
........
r58425 | neal.norwitz | 2007-10-11 20:52:34 -0700 (Thu, 11 Oct 2007) | 1 line
Get this module to compile with bsddb versions prior to 4.3
........
r58430 | martin.v.loewis | 2007-10-12 01:56:52 -0700 (Fri, 12 Oct 2007) | 3 lines
Bug #1216: Restore support for Visual Studio 2002.
Will backport to 2.5.
........
r58433 | raymond.hettinger | 2007-10-12 10:53:11 -0700 (Fri, 12 Oct 2007) | 1 line
Fix test of count.__repr__() to ignore the 'L' if the count is a long
........
r58434 | gregory.p.smith | 2007-10-12 11:44:06 -0700 (Fri, 12 Oct 2007) | 4 lines
Fixes http://bugs.python.org/issue1233 - bsddb.dbshelve.DBShelf.append
was useless due to inverted logic. Also adds a test case for RECNO dbs
to test_dbshelve.
........
r58445 | georg.brandl | 2007-10-13 06:20:03 -0700 (Sat, 13 Oct 2007) | 2 lines
Fix email example.
........
r58450 | gregory.p.smith | 2007-10-13 16:02:05 -0700 (Sat, 13 Oct 2007) | 2 lines
Fix an uncollectable reference leak in bsddb.db.DBShelf.append
........
r58453 | neal.norwitz | 2007-10-13 17:18:40 -0700 (Sat, 13 Oct 2007) | 8 lines
Let the O/S supply a port if none of the default ports can be used.
This should make the tests more robust at the expense of allowing
tests to be sloppier by not requiring them to cleanup after themselves.
(It will legitamitely help when running two test suites simultaneously
or if another process is already using one of the predefined ports.)
Also simplifies (slightLy) the exception handling elsewhere.
........
r58459 | neal.norwitz | 2007-10-14 11:30:21 -0700 (Sun, 14 Oct 2007) | 2 lines
Don't raise a string exception, they don't work anymore.
........
r58460 | neal.norwitz | 2007-10-14 11:40:37 -0700 (Sun, 14 Oct 2007) | 1 line
Use unittest for assertions
........
r58468 | armin.rigo | 2007-10-15 00:48:35 -0700 (Mon, 15 Oct 2007) | 2 lines
test_bigbits was not testing what it seemed to.
........
r58471 | guido.van.rossum | 2007-10-15 08:54:11 -0700 (Mon, 15 Oct 2007) | 3 lines
Change a PyErr_Print() into a PyErr_Clear(),
per discussion in issue 1031213.
........
r58500 | raymond.hettinger | 2007-10-16 12:18:30 -0700 (Tue, 16 Oct 2007) | 1 line
Improve error messages
........
r58506 | raymond.hettinger | 2007-10-16 14:28:32 -0700 (Tue, 16 Oct 2007) | 1 line
More docs, error messages, and tests
........
r58507 | andrew.kuchling | 2007-10-16 15:58:03 -0700 (Tue, 16 Oct 2007) | 1 line
Add items
........
r58508 | brett.cannon | 2007-10-16 16:24:06 -0700 (Tue, 16 Oct 2007) | 3 lines
Remove ``:const:`` notation on None in parameter list. Since the markup is not
rendered for parameters it just showed up as ``:const:`None` `` in the output.
........
r58509 | brett.cannon | 2007-10-16 16:26:45 -0700 (Tue, 16 Oct 2007) | 3 lines
Re-order some functions whose parameters differ between PyObject and const char
* so that they are next to each other.
........
r58522 | armin.rigo | 2007-10-17 11:46:37 -0700 (Wed, 17 Oct 2007) | 5 lines
Fix the overflow checking of list_repeat.
Introduce overflow checking into list_inplace_repeat.
Backport candidate, possibly.
........
r58530 | facundo.batista | 2007-10-17 20:16:03 -0700 (Wed, 17 Oct 2007) | 7 lines
Issue #1580738. When HTTPConnection reads the whole stream with read(),
it closes itself. When the stream is read in several calls to read(n),
it should behave in the same way if HTTPConnection knows where the end
of the stream is (through self.length). Added a test case for this
behaviour.
........
r58531 | facundo.batista | 2007-10-17 20:44:48 -0700 (Wed, 17 Oct 2007) | 3 lines
Issue 1289, just a typo.
........
r58532 | gregory.p.smith | 2007-10-18 00:56:54 -0700 (Thu, 18 Oct 2007) | 4 lines
cleanup test_dbtables to use mkdtemp. cleanup dbtables to pass txn as a
keyword argument whenever possible to avoid bugs and confusion. (dbtables.py
line 447 self.db.get using txn as a non-keyword was an actual bug due to this)
........
r58533 | gregory.p.smith | 2007-10-18 01:34:20 -0700 (Thu, 18 Oct 2007) | 4 lines
Fix a weird bug in dbtables: if it chose a random rowid string that contained
NULL bytes it would cause the database all sorts of problems in the future
leading to very strange random failures and corrupt dbtables.bsdTableDb dbs.
........
r58534 | gregory.p.smith | 2007-10-18 09:32:02 -0700 (Thu, 18 Oct 2007) | 3 lines
A cleaner fix than the one committed last night. Generate random rowids that
do not contain null bytes.
........
r58537 | gregory.p.smith | 2007-10-18 10:17:57 -0700 (Thu, 18 Oct 2007) | 2 lines
mention bsddb fixes.
........
r58538 | raymond.hettinger | 2007-10-18 14:13:06 -0700 (Thu, 18 Oct 2007) | 1 line
Remove useless warning
........
r58539 | gregory.p.smith | 2007-10-19 00:31:20 -0700 (Fri, 19 Oct 2007) | 2 lines
squelch the warning that this test is supposed to trigger.
........
r58542 | georg.brandl | 2007-10-19 05:32:39 -0700 (Fri, 19 Oct 2007) | 2 lines
Clarify wording for apply().
........
r58544 | mark.summerfield | 2007-10-19 05:48:17 -0700 (Fri, 19 Oct 2007) | 3 lines
Added a cross-ref to each other.
........
r58545 | georg.brandl | 2007-10-19 10:38:49 -0700 (Fri, 19 Oct 2007) | 2 lines
#1284: "S" means "seen", not unread.
........
r58548 | thomas.heller | 2007-10-19 11:11:41 -0700 (Fri, 19 Oct 2007) | 4 lines
Fix ctypes on 32-bit systems when Python is configured --with-system-ffi.
See also https://bugs.launchpad.net/bugs/72505.
Ported from release25-maint branch.
........
r58550 | facundo.batista | 2007-10-19 12:25:57 -0700 (Fri, 19 Oct 2007) | 8 lines
The constructor from tuple was way too permissive: it allowed bad
coefficient numbers, floats in the sign, and other details that
generated directly the wrong number in the best case, or triggered
misfunctionality in the alorithms.
Test cases added for these issues. Thanks Mark Dickinson.
........
r58559 | georg.brandl | 2007-10-20 06:22:53 -0700 (Sat, 20 Oct 2007) | 2 lines
Fix code being interpreted as a target.
........
r58561 | georg.brandl | 2007-10-20 06:36:24 -0700 (Sat, 20 Oct 2007) | 2 lines
Document new "cmdoption" directive.
........
r58562 | georg.brandl | 2007-10-20 08:21:22 -0700 (Sat, 20 Oct 2007) | 2 lines
Make a path more Unix-standardy.
........
r58564 | georg.brandl | 2007-10-20 10:51:39 -0700 (Sat, 20 Oct 2007) | 2 lines
Document new directive "envvar".
........
r58567 | georg.brandl | 2007-10-20 11:08:14 -0700 (Sat, 20 Oct 2007) | 6 lines
* Add new toplevel chapter, "Using Python." (how to install,
configure and setup python on different platforms -- at least
in theory.)
* Move the Python on Mac docs in that chapter.
* Add a new chapter about the command line invocation, by stargaming.
........
r58568 | georg.brandl | 2007-10-20 11:33:20 -0700 (Sat, 20 Oct 2007) | 2 lines
Change title, for now.
........
r58569 | georg.brandl | 2007-10-20 11:39:25 -0700 (Sat, 20 Oct 2007) | 2 lines
Add entry to ACKS.
........
r58570 | georg.brandl | 2007-10-20 12:05:45 -0700 (Sat, 20 Oct 2007) | 2 lines
Clarify -E docs.
........
r58571 | georg.brandl | 2007-10-20 12:08:36 -0700 (Sat, 20 Oct 2007) | 2 lines
Even more clarification.
........
r58572 | andrew.kuchling | 2007-10-20 12:25:37 -0700 (Sat, 20 Oct 2007) | 1 line
Fix protocol name
........
r58573 | andrew.kuchling | 2007-10-20 12:35:18 -0700 (Sat, 20 Oct 2007) | 1 line
Various items
........
r58574 | andrew.kuchling | 2007-10-20 12:39:35 -0700 (Sat, 20 Oct 2007) | 1 line
Use correct header line
........
r58576 | armin.rigo | 2007-10-21 02:14:15 -0700 (Sun, 21 Oct 2007) | 3 lines
Add a crasher for the long-standing issue with closing a file
while another thread uses it.
........
r58577 | georg.brandl | 2007-10-21 03:01:56 -0700 (Sun, 21 Oct 2007) | 2 lines
Remove duplicate crasher.
........
r58578 | georg.brandl | 2007-10-21 03:24:20 -0700 (Sun, 21 Oct 2007) | 2 lines
Unify "byte code" to "bytecode". Also sprinkle :term: markup for it.
........
r58579 | georg.brandl | 2007-10-21 03:32:54 -0700 (Sun, 21 Oct 2007) | 2 lines
Add markup to new function descriptions.
........
r58580 | georg.brandl | 2007-10-21 03:45:46 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for descriptors.
........
r58581 | georg.brandl | 2007-10-21 03:46:24 -0700 (Sun, 21 Oct 2007) | 2 lines
Unify "file-descriptor" to "file descriptor".
........
r58582 | georg.brandl | 2007-10-21 03:52:38 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term: for generators.
........
r58583 | georg.brandl | 2007-10-21 05:10:28 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for iterator.
........
r58584 | georg.brandl | 2007-10-21 05:15:05 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for "new-style class".
........
r58588 | neal.norwitz | 2007-10-21 21:47:54 -0700 (Sun, 21 Oct 2007) | 1 line
Add Chris Monson so he can edit PEPs.
........
r58594 | guido.van.rossum | 2007-10-22 09:27:19 -0700 (Mon, 22 Oct 2007) | 4 lines
Issue #1307, patch by Derek Shockey.
When "MAIL" is received without args, an exception happens instead of
sending a 501 syntax error response.
........
r58598 | travis.oliphant | 2007-10-22 19:40:56 -0700 (Mon, 22 Oct 2007) | 1 line
Add phuang patch from Issue 708374 which adds offset parameter to mmap module.
........
r58601 | neal.norwitz | 2007-10-22 22:44:27 -0700 (Mon, 22 Oct 2007) | 2 lines
Bug #1313, fix typo (wrong variable name) in example.
........
r58609 | georg.brandl | 2007-10-23 11:21:35 -0700 (Tue, 23 Oct 2007) | 2 lines
Update Pygments version from externals.
........
r58618 | guido.van.rossum | 2007-10-23 12:25:41 -0700 (Tue, 23 Oct 2007) | 3 lines
Issue 1307 by Derek Shockey, fox the same bug for RCPT.
Neal: please backport!
........
r58620 | raymond.hettinger | 2007-10-23 13:37:41 -0700 (Tue, 23 Oct 2007) | 1 line
Shorter name for namedtuple()
........
r58621 | andrew.kuchling | 2007-10-23 13:55:47 -0700 (Tue, 23 Oct 2007) | 1 line
Update name
........
r58622 | raymond.hettinger | 2007-10-23 14:23:07 -0700 (Tue, 23 Oct 2007) | 1 line
Fixup news entry
........
r58623 | raymond.hettinger | 2007-10-23 18:28:33 -0700 (Tue, 23 Oct 2007) | 1 line
Optimize sum() for integer and float inputs.
........
r58624 | raymond.hettinger | 2007-10-23 19:05:51 -0700 (Tue, 23 Oct 2007) | 1 line
Fixup error return and add support for intermixed ints and floats/
........
r58628 | vinay.sajip | 2007-10-24 03:47:06 -0700 (Wed, 24 Oct 2007) | 1 line
Bug #1321: Fixed logic error in TimedRotatingFileHandler.__init__()
........
r58641 | facundo.batista | 2007-10-24 12:11:08 -0700 (Wed, 24 Oct 2007) | 4 lines
Issue 1290. CharacterData.__repr__ was constructing a string
in response that keeped having a non-ascii character.
........
r58643 | thomas.heller | 2007-10-24 12:50:45 -0700 (Wed, 24 Oct 2007) | 1 line
Added unittest for calling a function with paramflags (backport from py3k branch).
........
r58645 | matthias.klose | 2007-10-24 13:00:44 -0700 (Wed, 24 Oct 2007) | 2 lines
- Build using system ffi library on arm*-linux*.
........
r58651 | georg.brandl | 2007-10-24 14:40:38 -0700 (Wed, 24 Oct 2007) | 2 lines
Bug #1287: make os.environ.pop() work as expected.
........
r58652 | raymond.hettinger | 2007-10-24 19:26:58 -0700 (Wed, 24 Oct 2007) | 1 line
Missing DECREFs
........
r58653 | matthias.klose | 2007-10-24 23:37:24 -0700 (Wed, 24 Oct 2007) | 2 lines
- Build using system ffi library on arm*-linux*, pass --with-system-ffi to CONFIG_ARGS
........
r58655 | thomas.heller | 2007-10-25 12:47:32 -0700 (Thu, 25 Oct 2007) | 2 lines
ffi_type_longdouble may be already #defined.
See issue 1324.
........
r58656 | kurt.kaiser | 2007-10-25 15:43:45 -0700 (Thu, 25 Oct 2007) | 3 lines
Correct an ancient bug in an unused path by removing that path: register() is
now idempotent.
........
r58660 | kurt.kaiser | 2007-10-25 17:10:09 -0700 (Thu, 25 Oct 2007) | 4 lines
1. Add comments to provide top-level documentation.
2. Refactor to use more descriptive names.
3. Enhance tests in main().
........
r58675 | georg.brandl | 2007-10-26 11:30:41 -0700 (Fri, 26 Oct 2007) | 2 lines
Fix new pop() method on os.environ on ignorecase-platforms.
........
r58696 | neal.norwitz | 2007-10-27 15:32:21 -0700 (Sat, 27 Oct 2007) | 1 line
Update URL for Pygments. 0.8.1 is no longer available
........
r58697 | hyeshik.chang | 2007-10-28 04:19:02 -0700 (Sun, 28 Oct 2007) | 3 lines
- Add support for FreeBSD 8 which is recently forked from FreeBSD 7.
- Regenerate IN module for most recent maintenance tree of FreeBSD 6 and 7.
........
r58698 | hyeshik.chang | 2007-10-28 05:38:09 -0700 (Sun, 28 Oct 2007) | 2 lines
Enable platform-specific tweaks for FreeBSD 8 (exactly same to FreeBSD 7's yet)
........
r58700 | kurt.kaiser | 2007-10-28 12:03:59 -0700 (Sun, 28 Oct 2007) | 2 lines
Add confirmation dialog before printing. Patch 1717170 Tal Einat.
........
r58706 | guido.van.rossum | 2007-10-29 13:52:45 -0700 (Mon, 29 Oct 2007) | 3 lines
Patch 1353 by Jacob Winther.
Add mp4 mapping to mimetypes.py.
........
r58709 | guido.van.rossum | 2007-10-29 15:15:05 -0700 (Mon, 29 Oct 2007) | 6 lines
Backport fixes for the code that decodes octal escapes (and for PyString
also hex escapes) -- this was reaching beyond the end of the input string
buffer, even though it is not supposed to be \0-terminated.
This has no visible effect but is clearly the correct thing to do.
(In 3.0 it had a visible effect after removing ob_sstate from PyString.)
........
r58710 | kurt.kaiser | 2007-10-29 19:38:54 -0700 (Mon, 29 Oct 2007) | 7 lines
check in Tal Einat's update to tabpage.py
Patch 1612746
M configDialog.py
M NEWS.txt
AM tabbedpages.py
........
r58715 | georg.brandl | 2007-10-30 10:51:18 -0700 (Tue, 30 Oct 2007) | 2 lines
Use correct markup.
........
r58716 | georg.brandl | 2007-10-30 10:57:12 -0700 (Tue, 30 Oct 2007) | 2 lines
Make example about hiding None return values at the prompt clearer.
........
r58728 | neal.norwitz | 2007-10-30 23:33:20 -0700 (Tue, 30 Oct 2007) | 1 line
Fix some compiler warnings for signed comparisons on Unix and Windows.
........
r58731 | martin.v.loewis | 2007-10-31 10:19:33 -0700 (Wed, 31 Oct 2007) | 2 lines
Adding Christian Heimes.
........
r58737 | raymond.hettinger | 2007-10-31 14:57:58 -0700 (Wed, 31 Oct 2007) | 1 line
Clarify the reasons why pickle is almost always better than marshal
........
r58739 | raymond.hettinger | 2007-10-31 15:15:49 -0700 (Wed, 31 Oct 2007) | 1 line
Sets are marshalable.
........
2007-11-01 17:32:30 -03:00
|
|
|
Python's :term:`generator`\s provide a convenient way to implement the iterator
|
|
|
|
protocol. If a container object's :meth:`__iter__` method is implemented as a
|
|
|
|
generator, it will automatically return an iterator object (technically, a
|
2012-10-12 07:42:08 -03:00
|
|
|
generator object) supplying the :meth:`__iter__` and :meth:`~generator.__next__`
|
|
|
|
methods.
|
Merged revisions 73004,73439,73496,73509,73529,73564,73576-73577,73595-73596,73605 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r73004 | jeffrey.yasskin | 2009-05-28 22:44:31 -0500 (Thu, 28 May 2009) | 5 lines
Fix nearly all compilation warnings under Apple gcc-4.0. Tested with OPT="-g
-Wall -Wstrict-prototypes -Werror" in both --with-pydebug mode and --without.
There's still a batch of non-prototype warnings in Xlib.h that I don't know how
to fix.
........
r73439 | benjamin.peterson | 2009-06-15 19:29:31 -0500 (Mon, 15 Jun 2009) | 1 line
don't mask encoding errors when decoding a string #6289
........
r73496 | vinay.sajip | 2009-06-21 12:37:27 -0500 (Sun, 21 Jun 2009) | 1 line
Issue #6314: logging.basicConfig() performs extra checks on the "level" argument.
........
r73509 | amaury.forgeotdarc | 2009-06-22 14:33:48 -0500 (Mon, 22 Jun 2009) | 2 lines
#4490 Fix sample code run by "python -m xml.sax.xmlreader"
........
r73529 | r.david.murray | 2009-06-23 13:02:46 -0500 (Tue, 23 Jun 2009) | 4 lines
Fix issue 5230 by having pydoc's safeimport check to see if the import
error was thrown from itself in order to decide if the module can't be
found. Thanks to Lucas Prado Melo for collaborating on the fix and tests.
........
r73564 | amaury.forgeotdarc | 2009-06-25 17:29:29 -0500 (Thu, 25 Jun 2009) | 6 lines
#2016 Fix a crash in function call when the **kwargs dictionary is mutated
during the function call setup.
This even gives a slight speedup, probably because tuple allocation
is faster than PyMem_NEW.
........
r73576 | benjamin.peterson | 2009-06-26 18:37:06 -0500 (Fri, 26 Jun 2009) | 1 line
document is_declared_global()
........
r73577 | benjamin.peterson | 2009-06-27 09:16:23 -0500 (Sat, 27 Jun 2009) | 1 line
link to extensive generator docs in the reference manual
........
r73595 | ezio.melotti | 2009-06-27 18:45:39 -0500 (Sat, 27 Jun 2009) | 1 line
stmt and setup can contain multiple statements, see #5896
........
r73596 | ezio.melotti | 2009-06-27 19:07:45 -0500 (Sat, 27 Jun 2009) | 1 line
Fixed a wrong apostrophe
........
r73605 | georg.brandl | 2009-06-28 07:10:18 -0500 (Sun, 28 Jun 2009) | 1 line
Remove stray pychecker directive.
........
2009-06-28 14:22:03 -03:00
|
|
|
More information about generators can be found in :ref:`the documentation for
|
|
|
|
the yield expression <yieldexpr>`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. _typesseq:
|
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Sequence Types --- :class:`list`, :class:`tuple`, :class:`range`
|
|
|
|
================================================================
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
There are three basic sequence types: lists, tuples, and range objects.
|
|
|
|
Additional sequence types tailored for processing of
|
|
|
|
:ref:`binary data <binaryseq>` and :ref:`text strings <textseq>` are
|
|
|
|
described in dedicated sections.
|
2009-01-18 06:40:25 -04:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. _typesseq-common:
|
|
|
|
|
|
|
|
Common Sequence Operations
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
.. index:: object: sequence
|
|
|
|
|
|
|
|
The operations in the following table are supported by most sequence types,
|
|
|
|
both mutable and immutable. The :class:`collections.abc.Sequence` ABC is
|
|
|
|
provided to make it easier to correctly implement these operations on
|
|
|
|
custom sequence types.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2014-10-31 05:41:46 -03:00
|
|
|
This table lists the sequence operations sorted in ascending priority. In the
|
|
|
|
table, *s* and *t* are sequences of the same type, *n*, *i*, *j* and *k* are
|
|
|
|
integers and *x* is an arbitrary object that meets any type and value
|
|
|
|
restrictions imposed by *s*.
|
2012-08-20 04:14:07 -03:00
|
|
|
|
|
|
|
The ``in`` and ``not in`` operations have the same priorities as the
|
|
|
|
comparison operations. The ``+`` (concatenation) and ``*`` (repetition)
|
2017-05-16 18:09:23 -03:00
|
|
|
operations have the same priority as the corresponding numeric operations. [3]_
|
2012-08-20 04:14:07 -03:00
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
.. index::
|
|
|
|
triple: operations on; sequence; types
|
|
|
|
builtin: len
|
|
|
|
builtin: min
|
|
|
|
builtin: max
|
|
|
|
pair: concatenation; operation
|
|
|
|
pair: repetition; operation
|
|
|
|
pair: subscript; operation
|
|
|
|
pair: slice; operation
|
|
|
|
operator: in
|
|
|
|
operator: not in
|
|
|
|
single: count() (sequence method)
|
|
|
|
single: index() (sequence method)
|
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
+--------------------------+--------------------------------+----------+
|
|
|
|
| Operation | Result | Notes |
|
|
|
|
+==========================+================================+==========+
|
|
|
|
| ``x in s`` | ``True`` if an item of *s* is | \(1) |
|
|
|
|
| | equal to *x*, else ``False`` | |
|
|
|
|
+--------------------------+--------------------------------+----------+
|
|
|
|
| ``x not in s`` | ``False`` if an item of *s* is | \(1) |
|
|
|
|
| | equal to *x*, else ``True`` | |
|
|
|
|
+--------------------------+--------------------------------+----------+
|
|
|
|
| ``s + t`` | the concatenation of *s* and | (6)(7) |
|
|
|
|
| | *t* | |
|
|
|
|
+--------------------------+--------------------------------+----------+
|
2015-09-06 23:08:55 -03:00
|
|
|
| ``s * n`` or | equivalent to adding *s* to | (2)(7) |
|
|
|
|
| ``n * s`` | itself *n* times | |
|
2012-08-20 04:14:07 -03:00
|
|
|
+--------------------------+--------------------------------+----------+
|
|
|
|
| ``s[i]`` | *i*\ th item of *s*, origin 0 | \(3) |
|
|
|
|
+--------------------------+--------------------------------+----------+
|
|
|
|
| ``s[i:j]`` | slice of *s* from *i* to *j* | (3)(4) |
|
|
|
|
+--------------------------+--------------------------------+----------+
|
|
|
|
| ``s[i:j:k]`` | slice of *s* from *i* to *j* | (3)(5) |
|
|
|
|
| | with step *k* | |
|
|
|
|
+--------------------------+--------------------------------+----------+
|
|
|
|
| ``len(s)`` | length of *s* | |
|
|
|
|
+--------------------------+--------------------------------+----------+
|
|
|
|
| ``min(s)`` | smallest item of *s* | |
|
|
|
|
+--------------------------+--------------------------------+----------+
|
|
|
|
| ``max(s)`` | largest item of *s* | |
|
|
|
|
+--------------------------+--------------------------------+----------+
|
2013-07-14 16:43:16 -03:00
|
|
|
| ``s.index(x[, i[, j]])`` | index of the first occurrence | \(8) |
|
2012-08-20 04:14:07 -03:00
|
|
|
| | of *x* in *s* (at or after | |
|
|
|
|
| | index *i* and before index *j*)| |
|
|
|
|
+--------------------------+--------------------------------+----------+
|
2013-07-14 16:43:16 -03:00
|
|
|
| ``s.count(x)`` | total number of occurrences of | |
|
2012-08-20 04:14:07 -03:00
|
|
|
| | *x* in *s* | |
|
|
|
|
+--------------------------+--------------------------------+----------+
|
|
|
|
|
|
|
|
Sequences of the same type also support comparisons. In particular, tuples
|
|
|
|
and lists are compared lexicographically by comparing corresponding elements.
|
|
|
|
This means that to compare equal, every element must compare equal and the
|
|
|
|
two sequences must be of the same type and have the same length. (For full
|
|
|
|
details see :ref:`comparisons` in the language reference.)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Notes:
|
|
|
|
|
|
|
|
(1)
|
2012-08-20 04:14:07 -03:00
|
|
|
While the ``in`` and ``not in`` operations are used only for simple
|
|
|
|
containment testing in the general case, some specialised sequences
|
|
|
|
(such as :class:`str`, :class:`bytes` and :class:`bytearray`) also use
|
|
|
|
them for subsequence testing::
|
|
|
|
|
|
|
|
>>> "gg" in "eggs"
|
|
|
|
True
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
(2)
|
|
|
|
Values of *n* less than ``0`` are treated as ``0`` (which yields an empty
|
2015-09-06 23:08:55 -03:00
|
|
|
sequence of the same type as *s*). Note that items in the sequence *s*
|
|
|
|
are not copied; they are referenced multiple times. This often haunts
|
|
|
|
new Python programmers; consider::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
>>> lists = [[]] * 3
|
|
|
|
>>> lists
|
|
|
|
[[], [], []]
|
|
|
|
>>> lists[0].append(3)
|
|
|
|
>>> lists
|
|
|
|
[[3], [3], [3]]
|
|
|
|
|
|
|
|
What has happened is that ``[[]]`` is a one-element list containing an empty
|
2015-09-06 23:08:55 -03:00
|
|
|
list, so all three elements of ``[[]] * 3`` are references to this single empty
|
Merged revisions 61724-61725,61731-61735,61737,61739,61741,61743-61744,61753,61761,61765-61767,61769,61773,61776-61778,61780-61783,61788,61793,61796,61807,61813 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sat, 22 Mar 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 M?\195?\164r 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 M?\195?\164r 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 M?\195?\164r 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 M?\195?\164r 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 M?\195?\164r 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 M?\195?\164r 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 M?\195?\164r 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 M?\195?\164r 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 M?\195?\164r 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 M?\195?\164r 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 M?\195?\164r 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sat, 22 Mar 2008) | 2 lines
Install lib2to3.
................
r61731 | facundo.batista | 2008-03-22 03:45:37 +0100 (Sat, 22 Mar 2008) | 4 lines
Small fix that complicated the test actually when that
test failed.
................
r61732 | alexandre.vassalotti | 2008-03-22 05:08:44 +0100 (Sat, 22 Mar 2008) | 2 lines
Added warning for the removal of 'hotshot' in Py3k.
................
r61733 | georg.brandl | 2008-03-22 11:07:29 +0100 (Sat, 22 Mar 2008) | 4 lines
#1918: document that weak references *to* an object are
cleared before the object's __del__ is called, to ensure that the weak
reference callback (if any) finds the object healthy.
................
r61734 | georg.brandl | 2008-03-22 11:56:23 +0100 (Sat, 22 Mar 2008) | 2 lines
Activate the Sphinx doctest extension and convert howto/functional to use it.
................
r61735 | georg.brandl | 2008-03-22 11:58:38 +0100 (Sat, 22 Mar 2008) | 2 lines
Allow giving source names on the cmdline.
................
r61737 | georg.brandl | 2008-03-22 12:00:48 +0100 (Sat, 22 Mar 2008) | 2 lines
Fixup this HOWTO's doctest blocks so that they can be run with sphinx' doctest builder.
................
r61739 | georg.brandl | 2008-03-22 12:47:10 +0100 (Sat, 22 Mar 2008) | 2 lines
Test decimal.rst doctests as far as possible with sphinx doctest.
................
r61741 | georg.brandl | 2008-03-22 13:04:26 +0100 (Sat, 22 Mar 2008) | 2 lines
Make doctests in re docs usable with sphinx' doctest.
................
r61743 | georg.brandl | 2008-03-22 13:59:37 +0100 (Sat, 22 Mar 2008) | 2 lines
Make more doctests in pprint docs testable.
................
r61744 | georg.brandl | 2008-03-22 14:07:06 +0100 (Sat, 22 Mar 2008) | 2 lines
No need to specify explicit "doctest_block" anymore.
................
r61753 | georg.brandl | 2008-03-22 21:08:43 +0100 (Sat, 22 Mar 2008) | 2 lines
Fix-up syntax problems.
................
r61761 | georg.brandl | 2008-03-22 22:06:20 +0100 (Sat, 22 Mar 2008) | 4 lines
Make collections' doctests executable.
(The <BLANKLINE>s will be stripped from presentation output.)
................
r61765 | georg.brandl | 2008-03-22 22:21:57 +0100 (Sat, 22 Mar 2008) | 2 lines
Test doctests in datetime docs.
................
r61766 | georg.brandl | 2008-03-22 22:26:44 +0100 (Sat, 22 Mar 2008) | 2 lines
Test doctests in operator docs.
................
r61767 | georg.brandl | 2008-03-22 22:38:33 +0100 (Sat, 22 Mar 2008) | 2 lines
Enable doctests in functions.rst. Already found two errors :)
................
r61769 | georg.brandl | 2008-03-22 23:04:10 +0100 (Sat, 22 Mar 2008) | 3 lines
Enable doctest running for several other documents.
We have now over 640 doctests that are run with "make doctest".
................
r61773 | raymond.hettinger | 2008-03-23 01:55:46 +0100 (Sun, 23 Mar 2008) | 1 line
Simplify demo code.
................
r61776 | neal.norwitz | 2008-03-23 04:43:33 +0100 (Sun, 23 Mar 2008) | 7 lines
Try to make this test a little more robust and not fail with:
timeout (10.0025) is more than 2 seconds more than expected (0.001)
I'm assuming this problem is caused by DNS lookup. This change
does a DNS lookup of the hostname before trying to connect, so the time
is not included.
................
r61777 | neal.norwitz | 2008-03-23 05:08:30 +0100 (Sun, 23 Mar 2008) | 1 line
Speed up the test by avoiding socket timeouts.
................
r61778 | neal.norwitz | 2008-03-23 05:43:09 +0100 (Sun, 23 Mar 2008) | 1 line
Skip the epoll test if epoll() does not work
................
r61780 | neal.norwitz | 2008-03-23 06:47:20 +0100 (Sun, 23 Mar 2008) | 1 line
Suppress failure (to avoid a flaky test) if we cannot connect to svn.python.org
................
r61781 | neal.norwitz | 2008-03-23 07:13:25 +0100 (Sun, 23 Mar 2008) | 4 lines
Move itertools before future_builtins since the latter depends on the former.
From a clean build importing future_builtins would fail since itertools
wasn't built yet.
................
r61782 | neal.norwitz | 2008-03-23 07:16:04 +0100 (Sun, 23 Mar 2008) | 1 line
Try to prevent the alarm going off early in tearDown
................
r61783 | neal.norwitz | 2008-03-23 07:19:57 +0100 (Sun, 23 Mar 2008) | 4 lines
Remove compiler warnings (on Alpha at least) about using chars as
array subscripts. Using chars are dangerous b/c they are signed
on some platforms and unsigned on others.
................
r61788 | georg.brandl | 2008-03-23 09:05:30 +0100 (Sun, 23 Mar 2008) | 2 lines
Make the doctests presentation-friendlier.
................
r61793 | amaury.forgeotdarc | 2008-03-23 10:55:29 +0100 (Sun, 23 Mar 2008) | 4 lines
#1477: ur'\U0010FFFF' raised in narrow unicode builds.
Corrected the raw-unicode-escape codec to use UTF-16 surrogates in
this case, just like the unicode-escape codec.
................
r61796 | raymond.hettinger | 2008-03-23 14:32:32 +0100 (Sun, 23 Mar 2008) | 1 line
Issue 1681432: Add triangular distribution the random module.
................
r61807 | raymond.hettinger | 2008-03-23 20:37:53 +0100 (Sun, 23 Mar 2008) | 4 lines
Adopt Nick's suggestion for useful default arguments.
Clean-up floating point issues by adding true division and float constants.
................
r61813 | gregory.p.smith | 2008-03-23 22:04:43 +0100 (Sun, 23 Mar 2008) | 6 lines
Fix gzip to deal with CRC's being signed values in Python 2.x properly and to
read 32bit values as unsigned to start with rather than applying signedness
fixups allover the place afterwards.
This hopefully fixes the test_tarfile failure on the alpha/tru64 buildbot.
................
2008-03-23 18:54:12 -03:00
|
|
|
list. Modifying any of the elements of ``lists`` modifies this single list.
|
2012-08-20 04:14:07 -03:00
|
|
|
You can create a list of different lists this way::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
>>> lists = [[] for i in range(3)]
|
|
|
|
>>> lists[0].append(3)
|
|
|
|
>>> lists[1].append(5)
|
|
|
|
>>> lists[2].append(7)
|
|
|
|
>>> lists
|
|
|
|
[[3], [5], [7]]
|
|
|
|
|
2015-09-06 23:08:55 -03:00
|
|
|
Further explanation is available in the FAQ entry
|
|
|
|
:ref:`faq-multidimensional-list`.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
(3)
|
2016-12-29 23:57:09 -04:00
|
|
|
If *i* or *j* is negative, the index is relative to the end of sequence *s*:
|
2007-10-23 15:17:00 -03:00
|
|
|
``len(s) + i`` or ``len(s) + j`` is substituted. But note that ``-0`` is
|
|
|
|
still ``0``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
(4)
|
|
|
|
The slice of *s* from *i* to *j* is defined as the sequence of items with index
|
|
|
|
*k* such that ``i <= k < j``. If *i* or *j* is greater than ``len(s)``, use
|
|
|
|
``len(s)``. If *i* is omitted or ``None``, use ``0``. If *j* is omitted or
|
|
|
|
``None``, use ``len(s)``. If *i* is greater than or equal to *j*, the slice is
|
|
|
|
empty.
|
|
|
|
|
|
|
|
(5)
|
|
|
|
The slice of *s* from *i* to *j* with step *k* is defined as the sequence of
|
Merged revisions 59512-59540 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59513 | raymond.hettinger | 2007-12-15 01:07:25 +0100 (Sat, 15 Dec 2007) | 6 lines
Optimize PyList_AsTuple(). Improve cache performance by doing the
pointer copy and object increment in one pass. For small lists,
save the overhead of the call to memcpy() -- this comes up in
calls like f(*listcomp).
........
r59519 | christian.heimes | 2007-12-15 06:38:35 +0100 (Sat, 15 Dec 2007) | 2 lines
Fixed #1624: Remove output comparison for test_pep277
I had to modify Brett's patch slightly.
........
r59520 | georg.brandl | 2007-12-15 10:34:59 +0100 (Sat, 15 Dec 2007) | 2 lines
Add note about future import needed for with statement.
........
r59522 | georg.brandl | 2007-12-15 10:36:37 +0100 (Sat, 15 Dec 2007) | 2 lines
Argh, wrong version.
........
r59524 | georg.brandl | 2007-12-16 12:06:09 +0100 (Sun, 16 Dec 2007) | 2 lines
Dummy commit to investigate #1617.
........
r59525 | georg.brandl | 2007-12-16 12:21:48 +0100 (Sun, 16 Dec 2007) | 2 lines
Revert dummy commit now that the build slave is building.
........
r59527 | georg.brandl | 2007-12-16 16:47:46 +0100 (Sun, 16 Dec 2007) | 2 lines
Remove orphaned footnote reference.
........
r59528 | georg.brandl | 2007-12-16 16:53:49 +0100 (Sun, 16 Dec 2007) | 2 lines
Remove gratuitous unicode character.
........
r59529 | georg.brandl | 2007-12-16 16:59:19 +0100 (Sun, 16 Dec 2007) | 2 lines
Remove another unnecessary Unicode character.
........
r59530 | georg.brandl | 2007-12-16 17:00:36 +0100 (Sun, 16 Dec 2007) | 2 lines
Remove curious space-like characters.
........
r59532 | georg.brandl | 2007-12-16 20:36:51 +0100 (Sun, 16 Dec 2007) | 2 lines
Adapt conf.py to new option names.
........
r59533 | christian.heimes | 2007-12-16 22:39:43 +0100 (Sun, 16 Dec 2007) | 1 line
Fixed #1638: %zd configure test fails on Linux
........
r59536 | georg.brandl | 2007-12-17 00:11:16 +0100 (Mon, 17 Dec 2007) | 2 lines
Simplify.
........
r59537 | georg.brandl | 2007-12-17 00:13:29 +0100 (Mon, 17 Dec 2007) | 2 lines
Use PEP 8.
........
r59539 | georg.brandl | 2007-12-17 00:15:07 +0100 (Mon, 17 Dec 2007) | 2 lines
Don't use quotes for non-string code.
........
r59540 | facundo.batista | 2007-12-17 15:18:42 +0100 (Mon, 17 Dec 2007) | 4 lines
Removed the private _rounding_decision: it was not needed, and the code
is now simpler. Thanks Mark Dickinson.
........
2007-12-17 16:04:13 -04:00
|
|
|
items with index ``x = i + n*k`` such that ``0 <= n < (j-i)/k``. In other words,
|
2007-08-15 11:28:22 -03:00
|
|
|
the indices are ``i``, ``i+k``, ``i+2*k``, ``i+3*k`` and so on, stopping when
|
2016-12-24 04:25:15 -04:00
|
|
|
*j* is reached (but never including *j*). When *k* is positive,
|
|
|
|
*i* and *j* are reduced to ``len(s)`` if they are greater.
|
|
|
|
When *k* is negative, *i* and *j* are reduced to ``len(s) - 1`` if
|
|
|
|
they are greater. If *i* or *j* are omitted or ``None``, they become
|
2007-08-15 11:28:22 -03:00
|
|
|
"end" values (which end depends on the sign of *k*). Note, *k* cannot be zero.
|
|
|
|
If *k* is ``None``, it is treated like ``1``.
|
|
|
|
|
|
|
|
(6)
|
2012-08-20 04:14:07 -03:00
|
|
|
Concatenating immutable sequences always results in a new object. This
|
|
|
|
means that building up a sequence by repeated concatenation will have a
|
|
|
|
quadratic runtime cost in the total sequence length. To get a linear
|
|
|
|
runtime cost, you must switch to one of the alternatives below:
|
2011-11-25 11:33:53 -04:00
|
|
|
|
|
|
|
* if concatenating :class:`str` objects, you can build a list and use
|
2015-11-01 23:37:02 -04:00
|
|
|
:meth:`str.join` at the end or else write to an :class:`io.StringIO`
|
2012-08-21 04:42:52 -03:00
|
|
|
instance and retrieve its value when complete
|
2011-11-25 11:33:53 -04:00
|
|
|
|
|
|
|
* if concatenating :class:`bytes` objects, you can similarly use
|
2012-08-20 04:14:07 -03:00
|
|
|
:meth:`bytes.join` or :class:`io.BytesIO`, or you can do in-place
|
|
|
|
concatenation with a :class:`bytearray` object. :class:`bytearray`
|
2012-08-21 04:42:52 -03:00
|
|
|
objects are mutable and have an efficient overallocation mechanism
|
2012-08-20 04:14:07 -03:00
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
* if concatenating :class:`tuple` objects, extend a :class:`list` instead
|
2012-08-20 04:14:07 -03:00
|
|
|
|
|
|
|
* for other types, investigate the relevant class documentation
|
|
|
|
|
|
|
|
|
|
|
|
(7)
|
|
|
|
Some sequence types (such as :class:`range`) only support item sequences
|
|
|
|
that follow specific patterns, and hence don't support sequence
|
|
|
|
concatenation or repetition.
|
|
|
|
|
|
|
|
(8)
|
|
|
|
``index`` raises :exc:`ValueError` when *x* is not found in *s*.
|
2017-12-12 06:58:26 -04:00
|
|
|
Not all implementations support passing the additional arguments *i* and *j*.
|
|
|
|
These arguments allow efficient searching of subsections of the sequence. Passing
|
|
|
|
the extra arguments is roughly equivalent to using ``s[i:j].index(x)``, only
|
2012-08-20 04:14:07 -03:00
|
|
|
without copying any data and with the returned index being relative to
|
|
|
|
the start of the sequence rather than the start of the slice.
|
|
|
|
|
|
|
|
|
|
|
|
.. _typesseq-immutable:
|
|
|
|
|
|
|
|
Immutable Sequence Types
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
.. index::
|
|
|
|
triple: immutable; sequence; types
|
|
|
|
object: tuple
|
2012-08-21 04:42:52 -03:00
|
|
|
builtin: hash
|
2012-08-20 04:14:07 -03:00
|
|
|
|
|
|
|
The only operation that immutable sequence types generally implement that is
|
|
|
|
not also implemented by mutable sequence types is support for the :func:`hash`
|
|
|
|
built-in.
|
|
|
|
|
|
|
|
This support allows immutable sequences, such as :class:`tuple` instances, to
|
|
|
|
be used as :class:`dict` keys and stored in :class:`set` and :class:`frozenset`
|
|
|
|
instances.
|
|
|
|
|
|
|
|
Attempting to hash an immutable sequence that contains unhashable values will
|
|
|
|
result in :exc:`TypeError`.
|
|
|
|
|
|
|
|
|
|
|
|
.. _typesseq-mutable:
|
|
|
|
|
|
|
|
Mutable Sequence Types
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
.. index::
|
|
|
|
triple: mutable; sequence; types
|
|
|
|
object: list
|
|
|
|
object: bytearray
|
|
|
|
|
|
|
|
The operations in the following table are defined on mutable sequence types.
|
|
|
|
The :class:`collections.abc.MutableSequence` ABC is provided to make it
|
|
|
|
easier to correctly implement these operations on custom sequence types.
|
|
|
|
|
|
|
|
In the table *s* is an instance of a mutable sequence type, *t* is any
|
|
|
|
iterable object and *x* is an arbitrary object that meets any type
|
|
|
|
and value restrictions imposed by *s* (for example, :class:`bytearray` only
|
|
|
|
accepts integers that meet the value restriction ``0 <= x <= 255``).
|
|
|
|
|
|
|
|
|
|
|
|
.. index::
|
|
|
|
triple: operations on; sequence; types
|
|
|
|
triple: operations on; list; type
|
|
|
|
pair: subscript; assignment
|
|
|
|
pair: slice; assignment
|
|
|
|
statement: del
|
|
|
|
single: append() (sequence method)
|
2012-08-21 04:42:52 -03:00
|
|
|
single: clear() (sequence method)
|
|
|
|
single: copy() (sequence method)
|
2012-08-20 04:14:07 -03:00
|
|
|
single: extend() (sequence method)
|
|
|
|
single: insert() (sequence method)
|
|
|
|
single: pop() (sequence method)
|
|
|
|
single: remove() (sequence method)
|
|
|
|
single: reverse() (sequence method)
|
|
|
|
|
|
|
|
+------------------------------+--------------------------------+---------------------+
|
|
|
|
| Operation | Result | Notes |
|
|
|
|
+==============================+================================+=====================+
|
|
|
|
| ``s[i] = x`` | item *i* of *s* is replaced by | |
|
|
|
|
| | *x* | |
|
|
|
|
+------------------------------+--------------------------------+---------------------+
|
|
|
|
| ``s[i:j] = t`` | slice of *s* from *i* to *j* | |
|
|
|
|
| | is replaced by the contents of | |
|
|
|
|
| | the iterable *t* | |
|
|
|
|
+------------------------------+--------------------------------+---------------------+
|
|
|
|
| ``del s[i:j]`` | same as ``s[i:j] = []`` | |
|
|
|
|
+------------------------------+--------------------------------+---------------------+
|
|
|
|
| ``s[i:j:k] = t`` | the elements of ``s[i:j:k]`` | \(1) |
|
|
|
|
| | are replaced by those of *t* | |
|
|
|
|
+------------------------------+--------------------------------+---------------------+
|
|
|
|
| ``del s[i:j:k]`` | removes the elements of | |
|
|
|
|
| | ``s[i:j:k]`` from the list | |
|
|
|
|
+------------------------------+--------------------------------+---------------------+
|
2012-08-21 04:42:52 -03:00
|
|
|
| ``s.append(x)`` | appends *x* to the end of the | |
|
|
|
|
| | sequence (same as | |
|
|
|
|
| | ``s[len(s):len(s)] = [x]``) | |
|
2012-08-20 04:14:07 -03:00
|
|
|
+------------------------------+--------------------------------+---------------------+
|
2012-08-21 04:42:52 -03:00
|
|
|
| ``s.clear()`` | removes all items from ``s`` | \(5) |
|
2012-08-20 04:14:07 -03:00
|
|
|
| | (same as ``del s[:]``) | |
|
|
|
|
+------------------------------+--------------------------------+---------------------+
|
2012-08-21 04:42:52 -03:00
|
|
|
| ``s.copy()`` | creates a shallow copy of ``s``| \(5) |
|
2012-08-20 04:14:07 -03:00
|
|
|
| | (same as ``s[:]``) | |
|
|
|
|
+------------------------------+--------------------------------+---------------------+
|
2015-10-03 04:46:04 -03:00
|
|
|
| ``s.extend(t)`` or | extends *s* with the | |
|
|
|
|
| ``s += t`` | contents of *t* (for the | |
|
|
|
|
| | most part the same as | |
|
2012-08-21 04:42:52 -03:00
|
|
|
| | ``s[len(s):len(s)] = t``) | |
|
2012-08-20 04:14:07 -03:00
|
|
|
+------------------------------+--------------------------------+---------------------+
|
2015-10-03 04:46:04 -03:00
|
|
|
| ``s *= n`` | updates *s* with its contents | \(6) |
|
|
|
|
| | repeated *n* times | |
|
|
|
|
+------------------------------+--------------------------------+---------------------+
|
2012-08-21 04:42:52 -03:00
|
|
|
| ``s.insert(i, x)`` | inserts *x* into *s* at the | |
|
|
|
|
| | index given by *i* | |
|
|
|
|
| | (same as ``s[i:i] = [x]``) | |
|
2012-08-20 04:14:07 -03:00
|
|
|
+------------------------------+--------------------------------+---------------------+
|
2012-08-21 04:42:52 -03:00
|
|
|
| ``s.pop([i])`` | retrieves the item at *i* and | \(2) |
|
|
|
|
| | also removes it from *s* | |
|
2012-08-20 04:14:07 -03:00
|
|
|
+------------------------------+--------------------------------+---------------------+
|
2012-08-21 04:42:52 -03:00
|
|
|
| ``s.remove(x)`` | remove the first item from *s* | \(3) |
|
|
|
|
| | where ``s[i] == x`` | |
|
2012-08-20 04:14:07 -03:00
|
|
|
+------------------------------+--------------------------------+---------------------+
|
|
|
|
| ``s.reverse()`` | reverses the items of *s* in | \(4) |
|
|
|
|
| | place | |
|
|
|
|
+------------------------------+--------------------------------+---------------------+
|
|
|
|
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
|
|
|
|
(1)
|
|
|
|
*t* must have the same length as the slice it is replacing.
|
|
|
|
|
|
|
|
(2)
|
|
|
|
The optional argument *i* defaults to ``-1``, so that by default the last
|
|
|
|
item is removed and returned.
|
|
|
|
|
|
|
|
(3)
|
|
|
|
``remove`` raises :exc:`ValueError` when *x* is not found in *s*.
|
|
|
|
|
|
|
|
(4)
|
|
|
|
The :meth:`reverse` method modifies the sequence in place for economy of
|
|
|
|
space when reversing a large sequence. To remind users that it operates by
|
|
|
|
side effect, it does not return the reversed sequence.
|
|
|
|
|
|
|
|
(5)
|
|
|
|
:meth:`clear` and :meth:`!copy` are included for consistency with the
|
|
|
|
interfaces of mutable containers that don't support slicing operations
|
|
|
|
(such as :class:`dict` and :class:`set`)
|
|
|
|
|
|
|
|
.. versionadded:: 3.3
|
|
|
|
:meth:`clear` and :meth:`!copy` methods.
|
|
|
|
|
2015-10-03 04:46:04 -03:00
|
|
|
(6)
|
|
|
|
The value *n* is an integer, or an object implementing
|
|
|
|
:meth:`~object.__index__`. Zero and negative values of *n* clear
|
|
|
|
the sequence. Items in the sequence are not copied; they are referenced
|
|
|
|
multiple times, as explained for ``s * n`` under :ref:`typesseq-common`.
|
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
|
|
|
|
.. _typesseq-list:
|
|
|
|
|
|
|
|
Lists
|
|
|
|
-----
|
|
|
|
|
|
|
|
.. index:: object: list
|
|
|
|
|
|
|
|
Lists are mutable sequences, typically used to store collections of
|
|
|
|
homogeneous items (where the precise degree of similarity will vary by
|
|
|
|
application).
|
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
.. class:: list([iterable])
|
|
|
|
|
|
|
|
Lists may be constructed in several ways:
|
|
|
|
|
|
|
|
* Using a pair of square brackets to denote the empty list: ``[]``
|
|
|
|
* Using square brackets, separating items with commas: ``[a]``, ``[a, b, c]``
|
|
|
|
* Using a list comprehension: ``[x for x in iterable]``
|
|
|
|
* Using the type constructor: ``list()`` or ``list(iterable)``
|
2012-08-20 04:14:07 -03:00
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
The constructor builds a list whose items are the same and in the same
|
|
|
|
order as *iterable*'s items. *iterable* may be either a sequence, a
|
|
|
|
container that supports iteration, or an iterator object. If *iterable*
|
|
|
|
is already a list, a copy is made and returned, similar to ``iterable[:]``.
|
|
|
|
For example, ``list('abc')`` returns ``['a', 'b', 'c']`` and
|
|
|
|
``list( (1, 2, 3) )`` returns ``[1, 2, 3]``.
|
|
|
|
If no argument is given, the constructor creates a new empty list, ``[]``.
|
2012-08-20 04:14:07 -03:00
|
|
|
|
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
Many other operations also produce lists, including the :func:`sorted`
|
|
|
|
built-in.
|
2012-08-20 04:14:07 -03:00
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
Lists implement all of the :ref:`common <typesseq-common>` and
|
|
|
|
:ref:`mutable <typesseq-mutable>` sequence operations. Lists also provide the
|
|
|
|
following additional method:
|
2012-08-20 04:14:07 -03:00
|
|
|
|
2017-07-14 16:57:19 -03:00
|
|
|
.. method:: list.sort(*, key=None, reverse=False)
|
2012-08-20 04:14:07 -03:00
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
This method sorts the list in place, using only ``<`` comparisons
|
|
|
|
between items. Exceptions are not suppressed - if any comparison operations
|
|
|
|
fail, the entire sort operation will fail (and the list will likely be left
|
|
|
|
in a partially modified state).
|
2012-08-20 04:14:07 -03:00
|
|
|
|
2013-11-22 15:58:34 -04:00
|
|
|
:meth:`sort` accepts two arguments that can only be passed by keyword
|
|
|
|
(:ref:`keyword-only arguments <keyword-only_parameter>`):
|
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
*key* specifies a function of one argument that is used to extract a
|
|
|
|
comparison key from each list element (for example, ``key=str.lower``).
|
|
|
|
The key corresponding to each item in the list is calculated once and
|
|
|
|
then used for the entire sorting process. The default value of ``None``
|
|
|
|
means that list items are sorted directly without calculating a separate
|
|
|
|
key value.
|
2012-08-20 04:14:07 -03:00
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
The :func:`functools.cmp_to_key` utility is available to convert a 2.x
|
|
|
|
style *cmp* function to a *key* function.
|
2012-08-20 04:14:07 -03:00
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
*reverse* is a boolean value. If set to ``True``, then the list elements
|
|
|
|
are sorted as if each comparison were reversed.
|
2012-08-20 04:14:07 -03:00
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
This method modifies the sequence in place for economy of space when
|
|
|
|
sorting a large sequence. To remind users that it operates by side
|
|
|
|
effect, it does not return the sorted sequence (use :func:`sorted` to
|
|
|
|
explicitly request a new sorted list instance).
|
2012-08-20 04:14:07 -03:00
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
The :meth:`sort` method is guaranteed to be stable. A sort is stable if it
|
|
|
|
guarantees not to change the relative order of elements that compare equal
|
|
|
|
--- this is helpful for sorting in multiple passes (for example, sort by
|
|
|
|
department, then by salary grade).
|
2012-08-20 04:14:07 -03:00
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
.. impl-detail::
|
|
|
|
|
|
|
|
While a list is being sorted, the effect of attempting to mutate, or even
|
|
|
|
inspect, the list is undefined. The C implementation of Python makes the
|
|
|
|
list appear empty for the duration, and raises :exc:`ValueError` if it can
|
|
|
|
detect that the list has been mutated during a sort.
|
2012-08-20 04:14:07 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. _typesseq-tuple:
|
|
|
|
|
|
|
|
Tuples
|
|
|
|
------
|
|
|
|
|
|
|
|
.. index:: object: tuple
|
|
|
|
|
|
|
|
Tuples are immutable sequences, typically used to store collections of
|
|
|
|
heterogeneous data (such as the 2-tuples produced by the :func:`enumerate`
|
|
|
|
built-in). Tuples are also used for cases where an immutable sequence of
|
|
|
|
homogeneous data is needed (such as allowing storage in a :class:`set` or
|
|
|
|
:class:`dict` instance).
|
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
.. class:: tuple([iterable])
|
|
|
|
|
|
|
|
Tuples may be constructed in a number of ways:
|
|
|
|
|
|
|
|
* Using a pair of parentheses to denote the empty tuple: ``()``
|
|
|
|
* Using a trailing comma for a singleton tuple: ``a,`` or ``(a,)``
|
|
|
|
* Separating items with commas: ``a, b, c`` or ``(a, b, c)``
|
|
|
|
* Using the :func:`tuple` built-in: ``tuple()`` or ``tuple(iterable)``
|
2012-08-20 04:14:07 -03:00
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
The constructor builds a tuple whose items are the same and in the same
|
|
|
|
order as *iterable*'s items. *iterable* may be either a sequence, a
|
|
|
|
container that supports iteration, or an iterator object. If *iterable*
|
|
|
|
is already a tuple, it is returned unchanged. For example,
|
|
|
|
``tuple('abc')`` returns ``('a', 'b', 'c')`` and
|
|
|
|
``tuple( [1, 2, 3] )`` returns ``(1, 2, 3)``.
|
|
|
|
If no argument is given, the constructor creates a new empty tuple, ``()``.
|
2012-08-20 04:14:07 -03:00
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
Note that it is actually the comma which makes a tuple, not the parentheses.
|
|
|
|
The parentheses are optional, except in the empty tuple case, or
|
|
|
|
when they are needed to avoid syntactic ambiguity. For example,
|
|
|
|
``f(a, b, c)`` is a function call with three arguments, while
|
|
|
|
``f((a, b, c))`` is a function call with a 3-tuple as the sole argument.
|
2012-08-20 04:14:07 -03:00
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
Tuples implement all of the :ref:`common <typesseq-common>` sequence
|
|
|
|
operations.
|
2012-08-20 04:14:07 -03:00
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
For heterogeneous collections of data where access by name is clearer than
|
|
|
|
access by index, :func:`collections.namedtuple` may be a more appropriate
|
|
|
|
choice than a simple tuple object.
|
2012-08-20 04:14:07 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. _typesseq-range:
|
|
|
|
|
|
|
|
Ranges
|
|
|
|
------
|
|
|
|
|
|
|
|
.. index:: object: range
|
|
|
|
|
|
|
|
The :class:`range` type represents an immutable sequence of numbers and is
|
2012-08-21 04:42:52 -03:00
|
|
|
commonly used for looping a specific number of times in :keyword:`for`
|
|
|
|
loops.
|
|
|
|
|
2012-09-14 00:35:09 -03:00
|
|
|
.. class:: range(stop)
|
|
|
|
range(start, stop[, step])
|
2012-08-21 04:42:52 -03:00
|
|
|
|
|
|
|
The arguments to the range constructor must be integers (either built-in
|
|
|
|
:class:`int` or any object that implements the ``__index__`` special
|
|
|
|
method). If the *step* argument is omitted, it defaults to ``1``.
|
|
|
|
If the *start* argument is omitted, it defaults to ``0``.
|
|
|
|
If *step* is zero, :exc:`ValueError` is raised.
|
|
|
|
|
|
|
|
For a positive *step*, the contents of a range ``r`` are determined by the
|
|
|
|
formula ``r[i] = start + step*i`` where ``i >= 0`` and
|
|
|
|
``r[i] < stop``.
|
|
|
|
|
|
|
|
For a negative *step*, the contents of the range are still determined by
|
|
|
|
the formula ``r[i] = start + step*i``, but the constraints are ``i >= 0``
|
|
|
|
and ``r[i] > stop``.
|
|
|
|
|
2013-01-26 19:33:04 -04:00
|
|
|
A range object will be empty if ``r[0]`` does not meet the value
|
2012-08-21 04:42:52 -03:00
|
|
|
constraint. Ranges do support negative indices, but these are interpreted
|
|
|
|
as indexing from the end of the sequence determined by the positive
|
|
|
|
indices.
|
|
|
|
|
|
|
|
Ranges containing absolute values larger than :data:`sys.maxsize` are
|
|
|
|
permitted but some features (such as :func:`len`) may raise
|
|
|
|
:exc:`OverflowError`.
|
2012-08-20 04:14:07 -03:00
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
Range examples::
|
2012-08-20 04:14:07 -03:00
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
>>> list(range(10))
|
|
|
|
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
|
|
>>> list(range(1, 11))
|
|
|
|
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
|
|
|
>>> list(range(0, 30, 5))
|
|
|
|
[0, 5, 10, 15, 20, 25]
|
|
|
|
>>> list(range(0, 10, 3))
|
|
|
|
[0, 3, 6, 9]
|
|
|
|
>>> list(range(0, -10, -1))
|
|
|
|
[0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
|
|
|
|
>>> list(range(0))
|
|
|
|
[]
|
|
|
|
>>> list(range(1, 0))
|
|
|
|
[]
|
|
|
|
|
|
|
|
Ranges implement all of the :ref:`common <typesseq-common>` sequence operations
|
|
|
|
except concatenation and repetition (due to the fact that range objects can
|
|
|
|
only represent sequences that follow a strict pattern and repetition and
|
|
|
|
concatenation will usually violate that pattern).
|
|
|
|
|
2016-02-25 15:17:45 -04:00
|
|
|
.. attribute:: start
|
2012-08-21 04:42:52 -03:00
|
|
|
|
|
|
|
The value of the *start* parameter (or ``0`` if the parameter was
|
|
|
|
not supplied)
|
|
|
|
|
2016-02-25 15:17:45 -04:00
|
|
|
.. attribute:: stop
|
2012-08-21 04:42:52 -03:00
|
|
|
|
|
|
|
The value of the *stop* parameter
|
|
|
|
|
2016-02-25 15:17:45 -04:00
|
|
|
.. attribute:: step
|
2012-08-21 04:42:52 -03:00
|
|
|
|
|
|
|
The value of the *step* parameter (or ``1`` if the parameter was
|
|
|
|
not supplied)
|
2012-08-20 04:14:07 -03:00
|
|
|
|
|
|
|
The advantage of the :class:`range` type over a regular :class:`list` or
|
|
|
|
:class:`tuple` is that a :class:`range` object will always take the same
|
|
|
|
(small) amount of memory, no matter the size of the range it represents (as it
|
|
|
|
only stores the ``start``, ``stop`` and ``step`` values, calculating individual
|
|
|
|
items and subranges as needed).
|
|
|
|
|
2013-10-09 08:02:31 -03:00
|
|
|
Range objects implement the :class:`collections.abc.Sequence` ABC, and provide
|
2012-08-21 04:42:52 -03:00
|
|
|
features such as containment tests, element index lookup, slicing and
|
|
|
|
support for negative indices (see :ref:`typesseq`):
|
|
|
|
|
|
|
|
>>> r = range(0, 20, 2)
|
|
|
|
>>> r
|
|
|
|
range(0, 20, 2)
|
|
|
|
>>> 11 in r
|
|
|
|
False
|
|
|
|
>>> 10 in r
|
|
|
|
True
|
|
|
|
>>> r.index(10)
|
|
|
|
5
|
|
|
|
>>> r[5]
|
|
|
|
10
|
|
|
|
>>> r[:5]
|
|
|
|
range(0, 10, 2)
|
|
|
|
>>> r[-1]
|
|
|
|
18
|
|
|
|
|
|
|
|
Testing range objects for equality with ``==`` and ``!=`` compares
|
|
|
|
them as sequences. That is, two range objects are considered equal if
|
|
|
|
they represent the same sequence of values. (Note that two range
|
2013-10-09 08:02:31 -03:00
|
|
|
objects that compare equal might have different :attr:`~range.start`,
|
|
|
|
:attr:`~range.stop` and :attr:`~range.step` attributes, for example
|
|
|
|
``range(0) == range(2, 1, 3)`` or ``range(0, 3, 2) == range(0, 4, 2)``.)
|
2012-08-21 04:42:52 -03:00
|
|
|
|
|
|
|
.. versionchanged:: 3.2
|
|
|
|
Implement the Sequence ABC.
|
|
|
|
Support slicing and negative indices.
|
|
|
|
Test :class:`int` objects for membership in constant time instead of
|
|
|
|
iterating through all items.
|
|
|
|
|
|
|
|
.. versionchanged:: 3.3
|
|
|
|
Define '==' and '!=' to compare range objects based on the
|
|
|
|
sequence of values they define (instead of comparing based on
|
|
|
|
object identity).
|
|
|
|
|
|
|
|
.. versionadded:: 3.3
|
2013-10-09 08:02:31 -03:00
|
|
|
The :attr:`~range.start`, :attr:`~range.stop` and :attr:`~range.step`
|
|
|
|
attributes.
|
2012-08-20 04:14:07 -03:00
|
|
|
|
2016-09-06 20:35:34 -03:00
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
* The `linspace recipe <http://code.activestate.com/recipes/579000/>`_
|
|
|
|
shows how to implement a lazy version of range that suitable for floating
|
|
|
|
point applications.
|
2012-08-20 04:14:07 -03:00
|
|
|
|
2012-11-20 21:45:51 -04:00
|
|
|
.. index::
|
|
|
|
single: string; text sequence type
|
2012-11-28 05:38:40 -04:00
|
|
|
single: str (built-in class); (see also string)
|
2012-11-20 21:45:51 -04:00
|
|
|
object: string
|
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. _textseq:
|
|
|
|
|
|
|
|
Text Sequence Type --- :class:`str`
|
|
|
|
===================================
|
|
|
|
|
2012-11-20 21:45:51 -04:00
|
|
|
Textual data in Python is handled with :class:`str` objects, or :dfn:`strings`.
|
|
|
|
Strings are immutable
|
2012-10-11 22:57:48 -03:00
|
|
|
:ref:`sequences <typesseq>` of Unicode code points. String literals are
|
2012-08-20 04:14:07 -03:00
|
|
|
written in a variety of ways:
|
|
|
|
|
|
|
|
* Single quotes: ``'allows embedded "double" quotes'``
|
|
|
|
* Double quotes: ``"allows embedded 'single' quotes"``.
|
|
|
|
* Triple quoted: ``'''Three single quotes'''``, ``"""Three double quotes"""``
|
|
|
|
|
|
|
|
Triple quoted strings may span multiple lines - all associated whitespace will
|
|
|
|
be included in the string literal.
|
|
|
|
|
|
|
|
String literals that are part of a single expression and have only whitespace
|
2012-08-21 04:42:52 -03:00
|
|
|
between them will be implicitly converted to a single string literal. That
|
|
|
|
is, ``("spam " "eggs") == "spam eggs"``.
|
2012-08-20 04:14:07 -03:00
|
|
|
|
|
|
|
See :ref:`strings` for more about the various forms of string literal,
|
|
|
|
including supported escape sequences, and the ``r`` ("raw") prefix that
|
|
|
|
disables most escape sequence processing.
|
|
|
|
|
2012-11-28 05:38:40 -04:00
|
|
|
Strings may also be created from other objects using the :class:`str`
|
|
|
|
constructor.
|
2012-08-20 04:14:07 -03:00
|
|
|
|
|
|
|
Since there is no separate "character" type, indexing a string produces
|
|
|
|
strings of length 1. That is, for a non-empty string *s*, ``s[0] == s[0:1]``.
|
|
|
|
|
2012-11-20 21:45:51 -04:00
|
|
|
.. index::
|
|
|
|
object: io.StringIO
|
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
There is also no mutable string type, but :meth:`str.join` or
|
|
|
|
:class:`io.StringIO` can be used to efficiently construct strings from
|
|
|
|
multiple fragments.
|
|
|
|
|
|
|
|
.. versionchanged:: 3.3
|
|
|
|
For backwards compatibility with the Python 2 series, the ``u`` prefix is
|
|
|
|
once again permitted on string literals. It has no effect on the meaning
|
|
|
|
of string literals and cannot be combined with the ``r`` prefix.
|
|
|
|
|
2012-11-28 05:38:40 -04:00
|
|
|
|
|
|
|
.. index::
|
|
|
|
single: string; str (built-in class)
|
|
|
|
|
|
|
|
.. class:: str(object='')
|
|
|
|
str(object=b'', encoding='utf-8', errors='strict')
|
|
|
|
|
|
|
|
Return a :ref:`string <textseq>` version of *object*. If *object* is not
|
|
|
|
provided, returns the empty string. Otherwise, the behavior of ``str()``
|
|
|
|
depends on whether *encoding* or *errors* is given, as follows.
|
|
|
|
|
|
|
|
If neither *encoding* nor *errors* is given, ``str(object)`` returns
|
|
|
|
:meth:`object.__str__() <object.__str__>`, which is the "informal" or nicely
|
|
|
|
printable string representation of *object*. For string objects, this is
|
|
|
|
the string itself. If *object* does not have a :meth:`~object.__str__`
|
|
|
|
method, then :func:`str` falls back to returning
|
|
|
|
:meth:`repr(object) <repr>`.
|
|
|
|
|
|
|
|
.. index::
|
|
|
|
single: buffer protocol; str (built-in class)
|
|
|
|
single: bytes; str (built-in class)
|
|
|
|
|
|
|
|
If at least one of *encoding* or *errors* is given, *object* should be a
|
2013-05-04 12:06:34 -03:00
|
|
|
:term:`bytes-like object` (e.g. :class:`bytes` or :class:`bytearray`). In
|
|
|
|
this case, if *object* is a :class:`bytes` (or :class:`bytearray`) object,
|
|
|
|
then ``str(bytes, encoding, errors)`` is equivalent to
|
2012-11-28 05:38:40 -04:00
|
|
|
:meth:`bytes.decode(encoding, errors) <bytes.decode>`. Otherwise, the bytes
|
|
|
|
object underlying the buffer object is obtained before calling
|
|
|
|
:meth:`bytes.decode`. See :ref:`binaryseq` and
|
|
|
|
:ref:`bufferobjects` for information on buffer objects.
|
|
|
|
|
|
|
|
Passing a :class:`bytes` object to :func:`str` without the *encoding*
|
|
|
|
or *errors* arguments falls under the first case of returning the informal
|
|
|
|
string representation (see also the :option:`-b` command-line option to
|
|
|
|
Python). For example::
|
|
|
|
|
|
|
|
>>> str(b'Zoot!')
|
|
|
|
"b'Zoot!'"
|
|
|
|
|
|
|
|
For more information on the ``str`` class and its methods, see
|
|
|
|
:ref:`textseq` and the :ref:`string-methods` section below. To output
|
2016-02-12 20:41:37 -04:00
|
|
|
formatted strings, see the :ref:`f-strings` and :ref:`formatstrings`
|
|
|
|
sections. In addition, see the :ref:`stringservices` section.
|
2012-11-28 05:38:40 -04:00
|
|
|
|
|
|
|
|
|
|
|
.. index::
|
|
|
|
pair: string; methods
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. _string-methods:
|
|
|
|
|
|
|
|
String Methods
|
|
|
|
--------------
|
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. index::
|
|
|
|
module: re
|
|
|
|
|
|
|
|
Strings implement all of the :ref:`common <typesseq-common>` sequence
|
|
|
|
operations, along with the additional methods described below.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Strings also support two styles of string formatting, one providing a large
|
|
|
|
degree of flexibility and customization (see :meth:`str.format`,
|
|
|
|
:ref:`formatstrings` and :ref:`string-formatting`) and the other based on C
|
|
|
|
``printf`` style formatting that handles a narrower range of types and is
|
|
|
|
slightly harder to use correctly, but is often faster for the cases it can
|
|
|
|
handle (:ref:`old-string-formatting`).
|
2007-09-20 15:22:40 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
The :ref:`textservices` section of the standard library covers a number of
|
|
|
|
other modules that provide various text related utilities (including regular
|
|
|
|
expression support in the :mod:`re` module).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. method:: str.capitalize()
|
|
|
|
|
2010-07-05 08:41:42 -03:00
|
|
|
Return a copy of the string with its first character capitalized and the
|
2010-07-05 23:08:36 -03:00
|
|
|
rest lowercased.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2012-01-14 14:23:30 -04:00
|
|
|
.. method:: str.casefold()
|
|
|
|
|
|
|
|
Return a casefolded copy of the string. Casefolded strings may be used for
|
2012-01-19 00:09:32 -04:00
|
|
|
caseless matching.
|
|
|
|
|
|
|
|
Casefolding is similar to lowercasing but more aggressive because it is
|
|
|
|
intended to remove all case distinctions in a string. For example, the German
|
|
|
|
lowercase letter ``'ß'`` is equivalent to ``"ss"``. Since it is already
|
|
|
|
lowercase, :meth:`lower` would do nothing to ``'ß'``; :meth:`casefold`
|
|
|
|
converts it to ``"ss"``.
|
|
|
|
|
|
|
|
The casefolding algorithm is described in section 3.13 of the Unicode
|
|
|
|
Standard.
|
2012-01-14 14:23:30 -04:00
|
|
|
|
|
|
|
.. versionadded:: 3.3
|
|
|
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. method:: str.center(width[, fillchar])
|
|
|
|
|
|
|
|
Return centered in a string of length *width*. Padding is done using the
|
2014-08-09 03:14:04 -03:00
|
|
|
specified *fillchar* (default is an ASCII space). The original string is
|
|
|
|
returned if *width* is less than or equal to ``len(s)``.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. method:: str.count(sub[, start[, end]])
|
|
|
|
|
Merged revisions 69803-69805,69840,69901,69905,69907,69924,69927,69987 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r69803 | georg.brandl | 2009-02-20 01:48:21 -0600 (Fri, 20 Feb 2009) | 1 line
#5327: fix a broken link by joining it.
........
r69804 | georg.brandl | 2009-02-20 02:22:21 -0600 (Fri, 20 Feb 2009) | 1 line
At least separate imports from other statements.
........
r69805 | georg.brandl | 2009-02-20 02:45:47 -0600 (Fri, 20 Feb 2009) | 2 lines
Fix punctuation.
........
r69840 | georg.brandl | 2009-02-21 13:09:40 -0600 (Sat, 21 Feb 2009) | 1 line
#5338, #5339: two types in the API manual.
........
r69901 | georg.brandl | 2009-02-23 05:24:46 -0600 (Mon, 23 Feb 2009) | 2 lines
#5349: C++ pure virtuals can also have an implementation.
........
r69905 | georg.brandl | 2009-02-23 09:51:27 -0600 (Mon, 23 Feb 2009) | 2 lines
#5352: str.count() counts non-overlapping instances.
........
r69907 | georg.brandl | 2009-02-23 12:33:48 -0600 (Mon, 23 Feb 2009) | 1 line
Fix grammar.
........
r69924 | benjamin.peterson | 2009-02-23 20:45:35 -0600 (Mon, 23 Feb 2009) | 1 line
update README on running tests
........
r69927 | neil.schemenauer | 2009-02-23 22:23:25 -0600 (Mon, 23 Feb 2009) | 1 line
Fix call to os.waitpid, it does not take keyword args.
........
r69987 | benjamin.peterson | 2009-02-25 18:30:11 -0600 (Wed, 25 Feb 2009) | 1 line
fix str.format()'s first arg #5371
........
2009-02-25 23:38:59 -04:00
|
|
|
Return the number of non-overlapping occurrences of substring *sub* in the
|
|
|
|
range [*start*, *end*]. Optional arguments *start* and *end* are
|
|
|
|
interpreted as in slice notation.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2010-11-07 14:41:46 -04:00
|
|
|
.. method:: str.encode(encoding="utf-8", errors="strict")
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-11-07 14:41:46 -04:00
|
|
|
Return an encoded version of the string as a bytes object. Default encoding
|
|
|
|
is ``'utf-8'``. *errors* may be given to set a different error handling scheme.
|
|
|
|
The default for *errors* is ``'strict'``, meaning that encoding errors raise
|
|
|
|
a :exc:`UnicodeError`. Other possible
|
2009-05-04 18:01:20 -03:00
|
|
|
values are ``'ignore'``, ``'replace'``, ``'xmlcharrefreplace'``,
|
|
|
|
``'backslashreplace'`` and any other name registered via
|
2015-01-06 10:22:00 -04:00
|
|
|
:func:`codecs.register_error`, see section :ref:`error-handlers`. For a
|
2009-05-04 18:01:20 -03:00
|
|
|
list of possible encodings, see section :ref:`standard-encodings`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2009-09-18 18:42:35 -03:00
|
|
|
.. versionchanged:: 3.1
|
2010-08-17 12:07:14 -03:00
|
|
|
Support for keyword arguments added.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. method:: str.endswith(suffix[, start[, end]])
|
|
|
|
|
|
|
|
Return ``True`` if the string ends with the specified *suffix*, otherwise return
|
|
|
|
``False``. *suffix* can also be a tuple of suffixes to look for. With optional
|
|
|
|
*start*, test beginning at that position. With optional *end*, stop comparing
|
|
|
|
at that position.
|
|
|
|
|
|
|
|
|
2013-11-16 13:10:57 -04:00
|
|
|
.. method:: str.expandtabs(tabsize=8)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2013-04-21 17:05:21 -03:00
|
|
|
Return a copy of the string where all tab characters are replaced by one or
|
|
|
|
more spaces, depending on the current column and the given tab size. Tab
|
|
|
|
positions occur every *tabsize* characters (default is 8, giving tab
|
|
|
|
positions at columns 0, 8, 16 and so on). To expand the string, the current
|
|
|
|
column is set to zero and the string is examined character by character. If
|
|
|
|
the character is a tab (``\t``), one or more space characters are inserted
|
|
|
|
in the result until the current column is equal to the next tab position.
|
|
|
|
(The tab character itself is not copied.) If the character is a newline
|
|
|
|
(``\n``) or return (``\r``), it is copied and the current column is reset to
|
|
|
|
zero. Any other character is copied unchanged and the current column is
|
|
|
|
incremented by one regardless of how the character is represented when
|
|
|
|
printed.
|
|
|
|
|
|
|
|
>>> '01\t012\t0123\t01234'.expandtabs()
|
|
|
|
'01 012 0123 01234'
|
|
|
|
>>> '01\t012\t0123\t01234'.expandtabs(4)
|
|
|
|
'01 012 0123 01234'
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. method:: str.find(sub[, start[, end]])
|
|
|
|
|
2016-01-03 21:57:10 -04:00
|
|
|
Return the lowest index in the string where substring *sub* is found within
|
|
|
|
the slice ``s[start:end]``. Optional arguments *start* and *end* are
|
|
|
|
interpreted as in slice notation. Return ``-1`` if *sub* is not found.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-05-08 21:54:30 -03:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
The :meth:`~str.find` method should be used only if you need to know the
|
|
|
|
position of *sub*. To check if *sub* is a substring or not, use the
|
|
|
|
:keyword:`in` operator::
|
|
|
|
|
|
|
|
>>> 'Py' in 'Python'
|
|
|
|
True
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
Merged revisions 69803-69805,69840,69901,69905,69907,69924,69927,69987 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r69803 | georg.brandl | 2009-02-20 01:48:21 -0600 (Fri, 20 Feb 2009) | 1 line
#5327: fix a broken link by joining it.
........
r69804 | georg.brandl | 2009-02-20 02:22:21 -0600 (Fri, 20 Feb 2009) | 1 line
At least separate imports from other statements.
........
r69805 | georg.brandl | 2009-02-20 02:45:47 -0600 (Fri, 20 Feb 2009) | 2 lines
Fix punctuation.
........
r69840 | georg.brandl | 2009-02-21 13:09:40 -0600 (Sat, 21 Feb 2009) | 1 line
#5338, #5339: two types in the API manual.
........
r69901 | georg.brandl | 2009-02-23 05:24:46 -0600 (Mon, 23 Feb 2009) | 2 lines
#5349: C++ pure virtuals can also have an implementation.
........
r69905 | georg.brandl | 2009-02-23 09:51:27 -0600 (Mon, 23 Feb 2009) | 2 lines
#5352: str.count() counts non-overlapping instances.
........
r69907 | georg.brandl | 2009-02-23 12:33:48 -0600 (Mon, 23 Feb 2009) | 1 line
Fix grammar.
........
r69924 | benjamin.peterson | 2009-02-23 20:45:35 -0600 (Mon, 23 Feb 2009) | 1 line
update README on running tests
........
r69927 | neil.schemenauer | 2009-02-23 22:23:25 -0600 (Mon, 23 Feb 2009) | 1 line
Fix call to os.waitpid, it does not take keyword args.
........
r69987 | benjamin.peterson | 2009-02-25 18:30:11 -0600 (Wed, 25 Feb 2009) | 1 line
fix str.format()'s first arg #5371
........
2009-02-25 23:38:59 -04:00
|
|
|
.. method:: str.format(*args, **kwargs)
|
2007-08-31 06:22:56 -03:00
|
|
|
|
2010-03-21 06:04:24 -03:00
|
|
|
Perform a string formatting operation. The string on which this method is
|
|
|
|
called can contain literal text or replacement fields delimited by braces
|
|
|
|
``{}``. Each replacement field contains either the numeric index of a
|
|
|
|
positional argument, or the name of a keyword argument. Returns a copy of
|
|
|
|
the string where each replacement field is replaced with the string value of
|
|
|
|
the corresponding argument.
|
2007-08-31 06:22:56 -03:00
|
|
|
|
|
|
|
>>> "The sum of 1 + 2 is {0}".format(1+2)
|
|
|
|
'The sum of 1 + 2 is 3'
|
|
|
|
|
|
|
|
See :ref:`formatstrings` for a description of the various formatting options
|
|
|
|
that can be specified in format strings.
|
|
|
|
|
|
|
|
|
2010-11-04 14:06:58 -03:00
|
|
|
.. method:: str.format_map(mapping)
|
|
|
|
|
2010-11-06 01:59:27 -03:00
|
|
|
Similar to ``str.format(**mapping)``, except that ``mapping`` is
|
2013-12-23 12:20:51 -04:00
|
|
|
used directly and not copied to a :class:`dict`. This is useful
|
2010-11-06 10:22:13 -03:00
|
|
|
if for example ``mapping`` is a dict subclass:
|
|
|
|
|
|
|
|
>>> class Default(dict):
|
|
|
|
... def __missing__(self, key):
|
|
|
|
... return key
|
|
|
|
...
|
|
|
|
>>> '{name} was born in {country}'.format_map(Default(name='Guido'))
|
|
|
|
'Guido was born in country'
|
|
|
|
|
|
|
|
.. versionadded:: 3.2
|
2010-11-04 14:06:58 -03:00
|
|
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. method:: str.index(sub[, start[, end]])
|
|
|
|
|
2014-08-09 03:14:04 -03:00
|
|
|
Like :meth:`~str.find`, but raise :exc:`ValueError` when the substring is
|
|
|
|
not found.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. method:: str.isalnum()
|
|
|
|
|
|
|
|
Return true if all characters in the string are alphanumeric and there is at
|
2010-12-22 22:58:25 -04:00
|
|
|
least one character, false otherwise. A character ``c`` is alphanumeric if one
|
|
|
|
of the following returns ``True``: ``c.isalpha()``, ``c.isdecimal()``,
|
|
|
|
``c.isdigit()``, or ``c.isnumeric()``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. method:: str.isalpha()
|
|
|
|
|
|
|
|
Return true if all characters in the string are alphabetic and there is at least
|
2010-12-22 22:58:25 -04:00
|
|
|
one character, false otherwise. Alphabetic characters are those characters defined
|
|
|
|
in the Unicode character database as "Letter", i.e., those with general category
|
|
|
|
property being one of "Lm", "Lt", "Lu", "Ll", or "Lo". Note that this is different
|
|
|
|
from the "Alphabetic" property defined in the Unicode Standard.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2008-07-01 12:50:04 -03:00
|
|
|
.. method:: str.isdecimal()
|
|
|
|
|
|
|
|
Return true if all characters in the string are decimal
|
|
|
|
characters and there is at least one character, false
|
2016-12-10 21:08:25 -04:00
|
|
|
otherwise. Decimal characters are those that can be used to form
|
|
|
|
numbers in base 10, e.g. U+0660, ARABIC-INDIC DIGIT
|
|
|
|
ZERO. Formally a decimal character is a character in the Unicode
|
|
|
|
General Category "Nd".
|
2009-01-03 17:18:54 -04:00
|
|
|
|
2008-07-01 12:50:04 -03:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. method:: str.isdigit()
|
|
|
|
|
|
|
|
Return true if all characters in the string are digits and there is at least one
|
2010-12-22 22:58:25 -04:00
|
|
|
character, false otherwise. Digits include decimal characters and digits that need
|
2016-12-10 21:08:25 -04:00
|
|
|
special handling, such as the compatibility superscript digits.
|
|
|
|
This covers digits which cannot be used to form numbers in base 10,
|
|
|
|
like the Kharosthi numbers. Formally, a digit is a character that has the
|
|
|
|
property value Numeric_Type=Digit or Numeric_Type=Decimal.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. method:: str.isidentifier()
|
|
|
|
|
|
|
|
Return true if the string is a valid identifier according to the language
|
2007-08-31 06:22:56 -03:00
|
|
|
definition, section :ref:`identifiers`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2013-03-23 12:21:12 -03:00
|
|
|
Use :func:`keyword.iskeyword` to test for reserved identifiers such as
|
|
|
|
:keyword:`def` and :keyword:`class`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. method:: str.islower()
|
|
|
|
|
2011-08-15 08:27:19 -03:00
|
|
|
Return true if all cased characters [4]_ in the string are lowercase and
|
|
|
|
there is at least one cased character, false otherwise.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2008-07-01 12:50:04 -03:00
|
|
|
.. method:: str.isnumeric()
|
|
|
|
|
|
|
|
Return true if all characters in the string are numeric
|
|
|
|
characters, and there is at least one character, false
|
|
|
|
otherwise. Numeric characters include digit characters, and all characters
|
|
|
|
that have the Unicode numeric value property, e.g. U+2155,
|
2010-12-22 22:58:25 -04:00
|
|
|
VULGAR FRACTION ONE FIFTH. Formally, numeric characters are those with the property
|
|
|
|
value Numeric_Type=Digit, Numeric_Type=Decimal or Numeric_Type=Numeric.
|
2008-07-01 12:50:04 -03:00
|
|
|
|
2009-01-03 17:18:54 -04:00
|
|
|
|
2008-06-11 15:37:52 -03:00
|
|
|
.. method:: str.isprintable()
|
|
|
|
|
|
|
|
Return true if all characters in the string are printable or the string is
|
|
|
|
empty, false otherwise. Nonprintable characters are those characters defined
|
|
|
|
in the Unicode character database as "Other" or "Separator", excepting the
|
|
|
|
ASCII space (0x20) which is considered printable. (Note that printable
|
|
|
|
characters in this context are those which should not be escaped when
|
|
|
|
:func:`repr` is invoked on a string. It has no bearing on the handling of
|
|
|
|
strings written to :data:`sys.stdout` or :data:`sys.stderr`.)
|
|
|
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. method:: str.isspace()
|
|
|
|
|
|
|
|
Return true if there are only whitespace characters in the string and there is
|
2010-12-22 22:58:25 -04:00
|
|
|
at least one character, false otherwise. Whitespace characters are those
|
|
|
|
characters defined in the Unicode character database as "Other" or "Separator"
|
|
|
|
and those with bidirectional property being one of "WS", "B", or "S".
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. method:: str.istitle()
|
|
|
|
|
|
|
|
Return true if the string is a titlecased string and there is at least one
|
|
|
|
character, for example uppercase characters may only follow uncased characters
|
|
|
|
and lowercase characters only cased ones. Return false otherwise.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: str.isupper()
|
|
|
|
|
2011-08-15 08:27:19 -03:00
|
|
|
Return true if all cased characters [4]_ in the string are uppercase and
|
|
|
|
there is at least one cased character, false otherwise.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
Merged revisions 75365,75394,75402-75403,75418,75459,75484,75592-75596,75600,75602-75607,75610-75613,75616-75617,75623,75627,75640,75647,75696,75795 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r75365 | georg.brandl | 2009-10-11 22:16:16 +0200 (So, 11 Okt 2009) | 1 line
Fix broken links found by "make linkcheck". scipy.org seems to be done right now, so I could not verify links going there.
........
r75394 | georg.brandl | 2009-10-13 20:10:59 +0200 (Di, 13 Okt 2009) | 1 line
Fix markup.
........
r75402 | georg.brandl | 2009-10-14 17:51:48 +0200 (Mi, 14 Okt 2009) | 1 line
#7125: fix typo.
........
r75403 | georg.brandl | 2009-10-14 17:57:46 +0200 (Mi, 14 Okt 2009) | 1 line
#7126: os.environ changes *do* take effect in subprocesses started with os.system().
........
r75418 | georg.brandl | 2009-10-14 20:48:32 +0200 (Mi, 14 Okt 2009) | 1 line
#7116: str.join() takes an iterable.
........
r75459 | georg.brandl | 2009-10-17 10:57:43 +0200 (Sa, 17 Okt 2009) | 1 line
Fix refleaks in _ctypes PyCSimpleType_New, which fixes the refleak seen in test___all__.
........
r75484 | georg.brandl | 2009-10-18 09:58:12 +0200 (So, 18 Okt 2009) | 1 line
Fix missing word.
........
r75592 | georg.brandl | 2009-10-22 09:05:48 +0200 (Do, 22 Okt 2009) | 1 line
Fix punctuation.
........
r75593 | georg.brandl | 2009-10-22 09:06:49 +0200 (Do, 22 Okt 2009) | 1 line
Revert unintended change.
........
r75594 | georg.brandl | 2009-10-22 09:56:02 +0200 (Do, 22 Okt 2009) | 1 line
Fix markup.
........
r75595 | georg.brandl | 2009-10-22 09:56:56 +0200 (Do, 22 Okt 2009) | 1 line
Fix duplicate target.
........
r75596 | georg.brandl | 2009-10-22 10:05:04 +0200 (Do, 22 Okt 2009) | 1 line
Add a new directive marking up implementation details and start using it.
........
r75600 | georg.brandl | 2009-10-22 13:01:46 +0200 (Do, 22 Okt 2009) | 1 line
Make it more robust.
........
r75602 | georg.brandl | 2009-10-22 13:28:06 +0200 (Do, 22 Okt 2009) | 1 line
Document new directive.
........
r75603 | georg.brandl | 2009-10-22 13:28:23 +0200 (Do, 22 Okt 2009) | 1 line
Allow short form with text as argument.
........
r75604 | georg.brandl | 2009-10-22 13:36:50 +0200 (Do, 22 Okt 2009) | 1 line
Fix stylesheet for multi-paragraph impl-details.
........
r75605 | georg.brandl | 2009-10-22 13:48:10 +0200 (Do, 22 Okt 2009) | 1 line
Use "impl-detail" directive where applicable.
........
r75606 | georg.brandl | 2009-10-22 17:00:06 +0200 (Do, 22 Okt 2009) | 1 line
#6324: membership test tries iteration via __iter__.
........
r75607 | georg.brandl | 2009-10-22 17:04:09 +0200 (Do, 22 Okt 2009) | 1 line
#7088: document new functions in signal as Unix-only.
........
r75610 | georg.brandl | 2009-10-22 17:27:24 +0200 (Do, 22 Okt 2009) | 1 line
Reorder __slots__ fine print and add a clarification.
........
r75611 | georg.brandl | 2009-10-22 17:42:32 +0200 (Do, 22 Okt 2009) | 1 line
#7035: improve docs of the various <method>_errors() functions, and give them docstrings.
........
r75612 | georg.brandl | 2009-10-22 17:52:15 +0200 (Do, 22 Okt 2009) | 1 line
#7156: document curses as Unix-only.
........
r75613 | georg.brandl | 2009-10-22 17:54:35 +0200 (Do, 22 Okt 2009) | 1 line
#6977: getopt does not support optional option arguments.
........
r75616 | georg.brandl | 2009-10-22 18:17:05 +0200 (Do, 22 Okt 2009) | 1 line
Add proper references.
........
r75617 | georg.brandl | 2009-10-22 18:20:55 +0200 (Do, 22 Okt 2009) | 1 line
Make printout margin important.
........
r75623 | georg.brandl | 2009-10-23 10:14:44 +0200 (Fr, 23 Okt 2009) | 1 line
#7188: fix optionxform() docs.
........
r75627 | fred.drake | 2009-10-23 15:04:51 +0200 (Fr, 23 Okt 2009) | 2 lines
add further note about what's passed to optionxform
........
r75640 | neil.schemenauer | 2009-10-23 21:58:17 +0200 (Fr, 23 Okt 2009) | 2 lines
Improve some docstrings in the 'warnings' module.
........
r75647 | georg.brandl | 2009-10-24 12:04:19 +0200 (Sa, 24 Okt 2009) | 1 line
Fix markup.
........
r75696 | georg.brandl | 2009-10-25 21:25:43 +0100 (So, 25 Okt 2009) | 1 line
Fix a demo.
........
r75795 | georg.brandl | 2009-10-27 16:10:22 +0100 (Di, 27 Okt 2009) | 1 line
Fix a strange mis-edit.
........
2009-10-27 12:28:25 -03:00
|
|
|
.. method:: str.join(iterable)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-05-31 23:49:01 -03:00
|
|
|
Return a string which is the concatenation of the strings in *iterable*.
|
|
|
|
A :exc:`TypeError` will be raised if there are any non-string values in
|
|
|
|
*iterable*, including :class:`bytes` objects. The separator between
|
|
|
|
elements is the string providing this method.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. method:: str.ljust(width[, fillchar])
|
|
|
|
|
2014-08-09 03:14:04 -03:00
|
|
|
Return the string left justified in a string of length *width*. Padding is
|
|
|
|
done using the specified *fillchar* (default is an ASCII space). The
|
|
|
|
original string is returned if *width* is less than or equal to ``len(s)``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. method:: str.lower()
|
|
|
|
|
2011-08-15 08:27:19 -03:00
|
|
|
Return a copy of the string with all the cased characters [4]_ converted to
|
|
|
|
lowercase.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-01-19 00:09:32 -04:00
|
|
|
The lowercasing algorithm used is described in section 3.13 of the Unicode
|
|
|
|
Standard.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. method:: str.lstrip([chars])
|
|
|
|
|
|
|
|
Return a copy of the string with leading characters removed. The *chars*
|
|
|
|
argument is a string specifying the set of characters to be removed. If omitted
|
|
|
|
or ``None``, the *chars* argument defaults to removing whitespace. The *chars*
|
2014-08-09 03:14:04 -03:00
|
|
|
argument is not a prefix; rather, all combinations of its values are stripped::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
>>> ' spacious '.lstrip()
|
|
|
|
'spacious '
|
|
|
|
>>> 'www.example.com'.lstrip('cmowz.')
|
|
|
|
'example.com'
|
|
|
|
|
|
|
|
|
2009-04-12 12:51:51 -03:00
|
|
|
.. staticmethod:: str.maketrans(x[, y[, z]])
|
2007-11-27 19:48:05 -04:00
|
|
|
|
|
|
|
This static method returns a translation table usable for :meth:`str.translate`.
|
|
|
|
|
|
|
|
If there is only one argument, it must be a dictionary mapping Unicode
|
|
|
|
ordinals (integers) or characters (strings of length 1) to Unicode ordinals,
|
2016-10-19 10:29:26 -03:00
|
|
|
strings (of arbitrary lengths) or ``None``. Character keys will then be
|
2007-11-27 19:48:05 -04:00
|
|
|
converted to ordinals.
|
|
|
|
|
|
|
|
If there are two arguments, they must be strings of equal length, and in the
|
|
|
|
resulting dictionary, each character in x will be mapped to the character at
|
|
|
|
the same position in y. If there is a third argument, it must be a string,
|
2016-10-19 10:29:26 -03:00
|
|
|
whose characters will be mapped to ``None`` in the result.
|
2007-11-27 19:48:05 -04:00
|
|
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. method:: str.partition(sep)
|
|
|
|
|
|
|
|
Split the string at the first occurrence of *sep*, and return a 3-tuple
|
|
|
|
containing the part before the separator, the separator itself, and the part
|
|
|
|
after the separator. If the separator is not found, return a 3-tuple containing
|
|
|
|
the string itself, followed by two empty strings.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: str.replace(old, new[, count])
|
|
|
|
|
|
|
|
Return a copy of the string with all occurrences of substring *old* replaced by
|
|
|
|
*new*. If the optional argument *count* is given, only the first *count*
|
|
|
|
occurrences are replaced.
|
|
|
|
|
|
|
|
|
2007-08-31 07:15:37 -03:00
|
|
|
.. method:: str.rfind(sub[, start[, end]])
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-04-27 19:58:50 -03:00
|
|
|
Return the highest index in the string where substring *sub* is found, such
|
|
|
|
that *sub* is contained within ``s[start:end]``. Optional arguments *start*
|
|
|
|
and *end* are interpreted as in slice notation. Return ``-1`` on failure.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. method:: str.rindex(sub[, start[, end]])
|
|
|
|
|
|
|
|
Like :meth:`rfind` but raises :exc:`ValueError` when the substring *sub* is not
|
|
|
|
found.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: str.rjust(width[, fillchar])
|
|
|
|
|
2014-08-09 03:14:04 -03:00
|
|
|
Return the string right justified in a string of length *width*. Padding is
|
|
|
|
done using the specified *fillchar* (default is an ASCII space). The
|
|
|
|
original string is returned if *width* is less than or equal to ``len(s)``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. method:: str.rpartition(sep)
|
|
|
|
|
|
|
|
Split the string at the last occurrence of *sep*, and return a 3-tuple
|
|
|
|
containing the part before the separator, the separator itself, and the part
|
|
|
|
after the separator. If the separator is not found, return a 3-tuple containing
|
|
|
|
two empty strings, followed by the string itself.
|
|
|
|
|
|
|
|
|
2012-02-26 03:39:55 -04:00
|
|
|
.. method:: str.rsplit(sep=None, maxsplit=-1)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Return a list of the words in the string, using *sep* as the delimiter string.
|
|
|
|
If *maxsplit* is given, at most *maxsplit* splits are done, the *rightmost*
|
|
|
|
ones. If *sep* is not specified or ``None``, any whitespace string is a
|
|
|
|
separator. Except for splitting from the right, :meth:`rsplit` behaves like
|
|
|
|
:meth:`split` which is described in detail below.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: str.rstrip([chars])
|
|
|
|
|
|
|
|
Return a copy of the string with trailing characters removed. The *chars*
|
|
|
|
argument is a string specifying the set of characters to be removed. If omitted
|
|
|
|
or ``None``, the *chars* argument defaults to removing whitespace. The *chars*
|
2014-08-09 03:14:04 -03:00
|
|
|
argument is not a suffix; rather, all combinations of its values are stripped::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
>>> ' spacious '.rstrip()
|
|
|
|
' spacious'
|
|
|
|
>>> 'mississippi'.rstrip('ipz')
|
|
|
|
'mississ'
|
|
|
|
|
|
|
|
|
2012-02-26 03:39:55 -04:00
|
|
|
.. method:: str.split(sep=None, maxsplit=-1)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2007-08-31 07:15:37 -03:00
|
|
|
Return a list of the words in the string, using *sep* as the delimiter
|
|
|
|
string. If *maxsplit* is given, at most *maxsplit* splits are done (thus,
|
|
|
|
the list will have at most ``maxsplit+1`` elements). If *maxsplit* is not
|
2012-05-10 09:30:42 -03:00
|
|
|
specified or ``-1``, then there is no limit on the number of splits
|
|
|
|
(all possible splits are made).
|
#1370: Finish the merge r58749, log below, by resolving all conflicts in Doc/.
Merged revisions 58221-58741 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58221 | georg.brandl | 2007-09-20 10:57:59 -0700 (Thu, 20 Sep 2007) | 2 lines
Patch #1181: add os.environ.clear() method.
........
r58225 | sean.reifschneider | 2007-09-20 23:33:28 -0700 (Thu, 20 Sep 2007) | 3 lines
Issue1704287: "make install" fails unless you do "make" first. Make
oldsharedmods and sharedmods in "libinstall".
........
r58232 | guido.van.rossum | 2007-09-22 13:18:03 -0700 (Sat, 22 Sep 2007) | 4 lines
Patch # 188 by Philip Jenvey.
Make tell() mark CRLF as a newline.
With unit test.
........
r58242 | georg.brandl | 2007-09-24 10:55:47 -0700 (Mon, 24 Sep 2007) | 2 lines
Fix typo and double word.
........
r58245 | georg.brandl | 2007-09-24 10:59:28 -0700 (Mon, 24 Sep 2007) | 2 lines
#1196: document default radix for int().
........
r58247 | georg.brandl | 2007-09-24 11:08:24 -0700 (Mon, 24 Sep 2007) | 2 lines
#1177: accept 2xx responses for https too, not only http.
........
r58249 | andrew.kuchling | 2007-09-24 16:45:51 -0700 (Mon, 24 Sep 2007) | 1 line
Remove stray odd character; grammar fix
........
r58250 | andrew.kuchling | 2007-09-24 16:46:28 -0700 (Mon, 24 Sep 2007) | 1 line
Typo fix
........
r58251 | andrew.kuchling | 2007-09-24 17:09:42 -0700 (Mon, 24 Sep 2007) | 1 line
Add various items
........
r58268 | vinay.sajip | 2007-09-26 22:34:45 -0700 (Wed, 26 Sep 2007) | 1 line
Change to flush and close logic to fix #1760556.
........
r58269 | vinay.sajip | 2007-09-26 22:38:51 -0700 (Wed, 26 Sep 2007) | 1 line
Change to basicConfig() to fix #1021.
........
r58270 | georg.brandl | 2007-09-26 23:26:58 -0700 (Wed, 26 Sep 2007) | 2 lines
#1208: document match object's boolean value.
........
r58271 | vinay.sajip | 2007-09-26 23:56:13 -0700 (Wed, 26 Sep 2007) | 1 line
Minor date change.
........
r58272 | vinay.sajip | 2007-09-27 00:35:10 -0700 (Thu, 27 Sep 2007) | 1 line
Change to LogRecord.__init__() to fix #1206. Note that archaic use of type(x) == types.DictType is because of keeping 1.5.2 compatibility. While this is much less relevant these days, there probably needs to be a separate commit for removing all archaic constructs at the same time.
........
r58288 | brett.cannon | 2007-09-30 12:45:10 -0700 (Sun, 30 Sep 2007) | 9 lines
tuple.__repr__ did not consider a reference loop as it is not possible from
Python code; but it is possible from C. object.__str__ had the issue of not
expecting a type to doing something within it's tp_str implementation that
could trigger an infinite recursion, but it could in C code.. Both found
thanks to BaseException and how it handles its repr.
Closes issue #1686386. Thanks to Thomas Herve for taking an initial stab at
coming up with a solution.
........
r58289 | brett.cannon | 2007-09-30 13:37:19 -0700 (Sun, 30 Sep 2007) | 3 lines
Fix error introduced by r58288; if a tuple is length 0 return its repr and
don't worry about any self-referring tuples.
........
r58294 | facundo.batista | 2007-10-02 10:01:24 -0700 (Tue, 02 Oct 2007) | 11 lines
Made the various is_* operations return booleans. This was discussed
with Cawlishaw by mail, and he basically confirmed that to these is_*
operations, there's no need to return Decimal(0) and Decimal(1) if
the language supports the False and True booleans.
Also added a few tests for the these functions in extra.decTest, since
they are mostly untested (apart from the doctests).
Thanks Mark Dickinson
........
r58295 | facundo.batista | 2007-10-02 11:21:18 -0700 (Tue, 02 Oct 2007) | 4 lines
Added a class to store the digits of log(10), so that they can be made
available when necessary without recomputing. Thanks Mark Dickinson
........
r58299 | mark.summerfield | 2007-10-03 01:53:21 -0700 (Wed, 03 Oct 2007) | 4 lines
Added note in footnote about string comparisons about
unicodedata.normalize().
........
r58304 | raymond.hettinger | 2007-10-03 14:18:11 -0700 (Wed, 03 Oct 2007) | 1 line
enumerate() is no longer bounded to using sequences shorter than LONG_MAX. The possibility of overflow was sending some newsgroup posters into a tizzy.
........
r58305 | raymond.hettinger | 2007-10-03 17:20:27 -0700 (Wed, 03 Oct 2007) | 1 line
itertools.count() no longer limited to sys.maxint.
........
r58306 | kurt.kaiser | 2007-10-03 18:49:54 -0700 (Wed, 03 Oct 2007) | 3 lines
Assume that the user knows when he wants to end the line; don't insert
something he didn't select or complete.
........
r58307 | kurt.kaiser | 2007-10-03 19:07:50 -0700 (Wed, 03 Oct 2007) | 2 lines
Remove unused theme that was causing a fault in p3k.
........
r58308 | kurt.kaiser | 2007-10-03 19:09:17 -0700 (Wed, 03 Oct 2007) | 2 lines
Clean up EditorWindow close.
........
r58309 | kurt.kaiser | 2007-10-03 19:53:07 -0700 (Wed, 03 Oct 2007) | 7 lines
textView cleanup. Patch 1718043 Tal Einat.
M idlelib/EditorWindow.py
M idlelib/aboutDialog.py
M idlelib/textView.py
M idlelib/NEWS.txt
........
r58310 | kurt.kaiser | 2007-10-03 20:11:12 -0700 (Wed, 03 Oct 2007) | 3 lines
configDialog cleanup. Patch 1730217 Tal Einat.
........
r58311 | neal.norwitz | 2007-10-03 23:00:48 -0700 (Wed, 03 Oct 2007) | 4 lines
Coverity #151: Remove deadcode.
All this code already exists above starting at line 653.
........
r58325 | fred.drake | 2007-10-04 19:46:12 -0700 (Thu, 04 Oct 2007) | 1 line
wrap lines to <80 characters before fixing errors
........
r58326 | raymond.hettinger | 2007-10-04 19:47:07 -0700 (Thu, 04 Oct 2007) | 6 lines
Add __asdict__() to NamedTuple and refine the docs.
Add maxlen support to deque() and fixup docs.
Partially fix __reduce__(). The None as a third arg was no longer supported.
Still needs work on __reduce__() to handle recursive inputs.
........
r58327 | fred.drake | 2007-10-04 19:48:32 -0700 (Thu, 04 Oct 2007) | 3 lines
move descriptions of ac_(in|out)_buffer_size to the right place
http://bugs.python.org/issue1053
........
r58329 | neal.norwitz | 2007-10-04 20:39:17 -0700 (Thu, 04 Oct 2007) | 3 lines
dict could be NULL, so we need to XDECREF.
Fix a compiler warning about passing a PyTypeObject* instead of PyObject*.
........
r58330 | neal.norwitz | 2007-10-04 20:41:19 -0700 (Thu, 04 Oct 2007) | 2 lines
Fix Coverity #158: Check the correct variable.
........
r58332 | neal.norwitz | 2007-10-04 22:01:38 -0700 (Thu, 04 Oct 2007) | 7 lines
Fix Coverity #159.
This code was broken if save() returned a negative number since i contained
a boolean value and then we compared i < 0 which should never be true.
Will backport (assuming it's necessary)
........
r58334 | neal.norwitz | 2007-10-04 22:29:17 -0700 (Thu, 04 Oct 2007) | 1 line
Add a note about fixing some more warnings found by Coverity.
........
r58338 | raymond.hettinger | 2007-10-05 12:07:31 -0700 (Fri, 05 Oct 2007) | 1 line
Restore BEGIN/END THREADS macros which were squashed in the previous checkin
........
r58343 | gregory.p.smith | 2007-10-06 00:48:10 -0700 (Sat, 06 Oct 2007) | 3 lines
Stab in the dark attempt to fix the test_bsddb3 failure on sparc and S-390
ubuntu buildbots.
........
r58344 | gregory.p.smith | 2007-10-06 00:51:59 -0700 (Sat, 06 Oct 2007) | 2 lines
Allows BerkeleyDB 4.6.x >= 4.6.21 for the bsddb module.
........
r58348 | gregory.p.smith | 2007-10-06 08:47:37 -0700 (Sat, 06 Oct 2007) | 3 lines
Use the host the author likely meant in the first place. pop.gmail.com is
reliable. gmail.org is someones personal domain.
........
r58351 | neal.norwitz | 2007-10-06 12:16:28 -0700 (Sat, 06 Oct 2007) | 3 lines
Ensure that this test will pass even if another test left an unwritable TESTFN.
Also use the safe unlink in test_support instead of rolling our own here.
........
r58368 | georg.brandl | 2007-10-08 00:50:24 -0700 (Mon, 08 Oct 2007) | 3 lines
#1123: fix the docs for the str.split(None, sep) case.
Also expand a few other methods' docs, which had more info in the deprecated string module docs.
........
r58369 | georg.brandl | 2007-10-08 01:06:05 -0700 (Mon, 08 Oct 2007) | 2 lines
Update docstring of sched, also remove an unused assignment.
........
r58370 | raymond.hettinger | 2007-10-08 02:14:28 -0700 (Mon, 08 Oct 2007) | 5 lines
Add comments to NamedTuple code.
Let the field spec be either a string or a non-string sequence (suggested by Martin Blais with use cases).
Improve the error message in the case of a SyntaxError (caused by a duplicate field name).
........
r58371 | raymond.hettinger | 2007-10-08 02:56:29 -0700 (Mon, 08 Oct 2007) | 1 line
Missed a line in the docs
........
r58372 | raymond.hettinger | 2007-10-08 03:11:51 -0700 (Mon, 08 Oct 2007) | 1 line
Better variable names
........
r58376 | georg.brandl | 2007-10-08 07:12:47 -0700 (Mon, 08 Oct 2007) | 3 lines
#1199: docs for tp_as_{number,sequence,mapping}, by Amaury Forgeot d'Arc.
No need to merge this to py3k!
........
r58380 | raymond.hettinger | 2007-10-08 14:26:58 -0700 (Mon, 08 Oct 2007) | 1 line
Eliminate camelcase function name
........
r58381 | andrew.kuchling | 2007-10-08 16:23:03 -0700 (Mon, 08 Oct 2007) | 1 line
Eliminate camelcase function name
........
r58382 | raymond.hettinger | 2007-10-08 18:36:23 -0700 (Mon, 08 Oct 2007) | 1 line
Make the error messages more specific
........
r58384 | gregory.p.smith | 2007-10-08 23:02:21 -0700 (Mon, 08 Oct 2007) | 10 lines
Splits Modules/_bsddb.c up into bsddb.h and _bsddb.c and adds a C API
object available as bsddb.db.api. This is based on the patch submitted
by Duncan Grisby here:
http://sourceforge.net/tracker/index.php?func=detail&aid=1551895&group_id=13900&atid=313900
See this thread for additional info:
http://sourceforge.net/mailarchive/forum.php?thread_name=E1GAVDK-0002rk-Iw%40apasphere.com&forum_name=pybsddb-users
It also cleans up the code a little by removing some ifdef/endifs for
python prior to 2.1 and for unsupported Berkeley DB <= 3.2.
........
r58385 | gregory.p.smith | 2007-10-08 23:50:43 -0700 (Mon, 08 Oct 2007) | 5 lines
Fix a double free when positioning a database cursor to a non-existant
string key (and probably a few other situations with string keys).
This was reported with a patch as pybsddb sourceforge bug 1708868 by
jjjhhhlll at gmail.
........
r58386 | gregory.p.smith | 2007-10-09 00:19:11 -0700 (Tue, 09 Oct 2007) | 3 lines
Use the highest cPickle protocol in bsddb.dbshelve. This comes from
sourceforge pybsddb patch 1551443 by w_barnes.
........
r58394 | gregory.p.smith | 2007-10-09 11:26:02 -0700 (Tue, 09 Oct 2007) | 2 lines
remove another sleepycat reference
........
r58396 | kurt.kaiser | 2007-10-09 12:31:30 -0700 (Tue, 09 Oct 2007) | 3 lines
Allow interrupt only when executing user code in subprocess
Patch 1225 Tal Einat modified from IDLE-Spoon.
........
r58399 | brett.cannon | 2007-10-09 17:07:50 -0700 (Tue, 09 Oct 2007) | 5 lines
Remove file-level typedefs that were inconsistently used throughout the file.
Just move over to the public API names.
Closes issue1238.
........
r58401 | raymond.hettinger | 2007-10-09 17:26:46 -0700 (Tue, 09 Oct 2007) | 1 line
Accept Jim Jewett's api suggestion to use None instead of -1 to indicate unbounded deques.
........
r58403 | kurt.kaiser | 2007-10-09 17:55:40 -0700 (Tue, 09 Oct 2007) | 2 lines
Allow cursor color change w/o restart. Patch 1725576 Tal Einat.
........
r58404 | kurt.kaiser | 2007-10-09 18:06:47 -0700 (Tue, 09 Oct 2007) | 2 lines
show paste if > 80 columns. Patch 1659326 Tal Einat.
........
r58415 | thomas.heller | 2007-10-11 12:51:32 -0700 (Thu, 11 Oct 2007) | 5 lines
On OS X, use os.uname() instead of gestalt.sysv(...) to get the
operating system version. This allows to use ctypes when Python
was configured with --disable-toolbox-glue.
........
r58419 | neal.norwitz | 2007-10-11 20:01:01 -0700 (Thu, 11 Oct 2007) | 1 line
Get rid of warning about not being able to create an existing directory.
........
r58420 | neal.norwitz | 2007-10-11 20:01:30 -0700 (Thu, 11 Oct 2007) | 1 line
Get rid of warnings on a bunch of platforms by using a proper prototype.
........
r58421 | neal.norwitz | 2007-10-11 20:01:54 -0700 (Thu, 11 Oct 2007) | 4 lines
Get rid of compiler warning about retval being used (returned) without
being initialized. (gcc warning and Coverity 202)
........
r58422 | neal.norwitz | 2007-10-11 20:03:23 -0700 (Thu, 11 Oct 2007) | 1 line
Fix Coverity 168: Close the file before returning (exiting).
........
r58423 | neal.norwitz | 2007-10-11 20:04:18 -0700 (Thu, 11 Oct 2007) | 4 lines
Fix Coverity 180: Don't overallocate. We don't need structs, but pointers.
Also fix a memory leak.
........
r58424 | neal.norwitz | 2007-10-11 20:05:19 -0700 (Thu, 11 Oct 2007) | 5 lines
Fix Coverity 185-186: If the passed in FILE is NULL, uninitialized memory
would be accessed.
Will backport.
........
r58425 | neal.norwitz | 2007-10-11 20:52:34 -0700 (Thu, 11 Oct 2007) | 1 line
Get this module to compile with bsddb versions prior to 4.3
........
r58430 | martin.v.loewis | 2007-10-12 01:56:52 -0700 (Fri, 12 Oct 2007) | 3 lines
Bug #1216: Restore support for Visual Studio 2002.
Will backport to 2.5.
........
r58433 | raymond.hettinger | 2007-10-12 10:53:11 -0700 (Fri, 12 Oct 2007) | 1 line
Fix test of count.__repr__() to ignore the 'L' if the count is a long
........
r58434 | gregory.p.smith | 2007-10-12 11:44:06 -0700 (Fri, 12 Oct 2007) | 4 lines
Fixes http://bugs.python.org/issue1233 - bsddb.dbshelve.DBShelf.append
was useless due to inverted logic. Also adds a test case for RECNO dbs
to test_dbshelve.
........
r58445 | georg.brandl | 2007-10-13 06:20:03 -0700 (Sat, 13 Oct 2007) | 2 lines
Fix email example.
........
r58450 | gregory.p.smith | 2007-10-13 16:02:05 -0700 (Sat, 13 Oct 2007) | 2 lines
Fix an uncollectable reference leak in bsddb.db.DBShelf.append
........
r58453 | neal.norwitz | 2007-10-13 17:18:40 -0700 (Sat, 13 Oct 2007) | 8 lines
Let the O/S supply a port if none of the default ports can be used.
This should make the tests more robust at the expense of allowing
tests to be sloppier by not requiring them to cleanup after themselves.
(It will legitamitely help when running two test suites simultaneously
or if another process is already using one of the predefined ports.)
Also simplifies (slightLy) the exception handling elsewhere.
........
r58459 | neal.norwitz | 2007-10-14 11:30:21 -0700 (Sun, 14 Oct 2007) | 2 lines
Don't raise a string exception, they don't work anymore.
........
r58460 | neal.norwitz | 2007-10-14 11:40:37 -0700 (Sun, 14 Oct 2007) | 1 line
Use unittest for assertions
........
r58468 | armin.rigo | 2007-10-15 00:48:35 -0700 (Mon, 15 Oct 2007) | 2 lines
test_bigbits was not testing what it seemed to.
........
r58471 | guido.van.rossum | 2007-10-15 08:54:11 -0700 (Mon, 15 Oct 2007) | 3 lines
Change a PyErr_Print() into a PyErr_Clear(),
per discussion in issue 1031213.
........
r58500 | raymond.hettinger | 2007-10-16 12:18:30 -0700 (Tue, 16 Oct 2007) | 1 line
Improve error messages
........
r58506 | raymond.hettinger | 2007-10-16 14:28:32 -0700 (Tue, 16 Oct 2007) | 1 line
More docs, error messages, and tests
........
r58507 | andrew.kuchling | 2007-10-16 15:58:03 -0700 (Tue, 16 Oct 2007) | 1 line
Add items
........
r58508 | brett.cannon | 2007-10-16 16:24:06 -0700 (Tue, 16 Oct 2007) | 3 lines
Remove ``:const:`` notation on None in parameter list. Since the markup is not
rendered for parameters it just showed up as ``:const:`None` `` in the output.
........
r58509 | brett.cannon | 2007-10-16 16:26:45 -0700 (Tue, 16 Oct 2007) | 3 lines
Re-order some functions whose parameters differ between PyObject and const char
* so that they are next to each other.
........
r58522 | armin.rigo | 2007-10-17 11:46:37 -0700 (Wed, 17 Oct 2007) | 5 lines
Fix the overflow checking of list_repeat.
Introduce overflow checking into list_inplace_repeat.
Backport candidate, possibly.
........
r58530 | facundo.batista | 2007-10-17 20:16:03 -0700 (Wed, 17 Oct 2007) | 7 lines
Issue #1580738. When HTTPConnection reads the whole stream with read(),
it closes itself. When the stream is read in several calls to read(n),
it should behave in the same way if HTTPConnection knows where the end
of the stream is (through self.length). Added a test case for this
behaviour.
........
r58531 | facundo.batista | 2007-10-17 20:44:48 -0700 (Wed, 17 Oct 2007) | 3 lines
Issue 1289, just a typo.
........
r58532 | gregory.p.smith | 2007-10-18 00:56:54 -0700 (Thu, 18 Oct 2007) | 4 lines
cleanup test_dbtables to use mkdtemp. cleanup dbtables to pass txn as a
keyword argument whenever possible to avoid bugs and confusion. (dbtables.py
line 447 self.db.get using txn as a non-keyword was an actual bug due to this)
........
r58533 | gregory.p.smith | 2007-10-18 01:34:20 -0700 (Thu, 18 Oct 2007) | 4 lines
Fix a weird bug in dbtables: if it chose a random rowid string that contained
NULL bytes it would cause the database all sorts of problems in the future
leading to very strange random failures and corrupt dbtables.bsdTableDb dbs.
........
r58534 | gregory.p.smith | 2007-10-18 09:32:02 -0700 (Thu, 18 Oct 2007) | 3 lines
A cleaner fix than the one committed last night. Generate random rowids that
do not contain null bytes.
........
r58537 | gregory.p.smith | 2007-10-18 10:17:57 -0700 (Thu, 18 Oct 2007) | 2 lines
mention bsddb fixes.
........
r58538 | raymond.hettinger | 2007-10-18 14:13:06 -0700 (Thu, 18 Oct 2007) | 1 line
Remove useless warning
........
r58539 | gregory.p.smith | 2007-10-19 00:31:20 -0700 (Fri, 19 Oct 2007) | 2 lines
squelch the warning that this test is supposed to trigger.
........
r58542 | georg.brandl | 2007-10-19 05:32:39 -0700 (Fri, 19 Oct 2007) | 2 lines
Clarify wording for apply().
........
r58544 | mark.summerfield | 2007-10-19 05:48:17 -0700 (Fri, 19 Oct 2007) | 3 lines
Added a cross-ref to each other.
........
r58545 | georg.brandl | 2007-10-19 10:38:49 -0700 (Fri, 19 Oct 2007) | 2 lines
#1284: "S" means "seen", not unread.
........
r58548 | thomas.heller | 2007-10-19 11:11:41 -0700 (Fri, 19 Oct 2007) | 4 lines
Fix ctypes on 32-bit systems when Python is configured --with-system-ffi.
See also https://bugs.launchpad.net/bugs/72505.
Ported from release25-maint branch.
........
r58550 | facundo.batista | 2007-10-19 12:25:57 -0700 (Fri, 19 Oct 2007) | 8 lines
The constructor from tuple was way too permissive: it allowed bad
coefficient numbers, floats in the sign, and other details that
generated directly the wrong number in the best case, or triggered
misfunctionality in the alorithms.
Test cases added for these issues. Thanks Mark Dickinson.
........
r58559 | georg.brandl | 2007-10-20 06:22:53 -0700 (Sat, 20 Oct 2007) | 2 lines
Fix code being interpreted as a target.
........
r58561 | georg.brandl | 2007-10-20 06:36:24 -0700 (Sat, 20 Oct 2007) | 2 lines
Document new "cmdoption" directive.
........
r58562 | georg.brandl | 2007-10-20 08:21:22 -0700 (Sat, 20 Oct 2007) | 2 lines
Make a path more Unix-standardy.
........
r58564 | georg.brandl | 2007-10-20 10:51:39 -0700 (Sat, 20 Oct 2007) | 2 lines
Document new directive "envvar".
........
r58567 | georg.brandl | 2007-10-20 11:08:14 -0700 (Sat, 20 Oct 2007) | 6 lines
* Add new toplevel chapter, "Using Python." (how to install,
configure and setup python on different platforms -- at least
in theory.)
* Move the Python on Mac docs in that chapter.
* Add a new chapter about the command line invocation, by stargaming.
........
r58568 | georg.brandl | 2007-10-20 11:33:20 -0700 (Sat, 20 Oct 2007) | 2 lines
Change title, for now.
........
r58569 | georg.brandl | 2007-10-20 11:39:25 -0700 (Sat, 20 Oct 2007) | 2 lines
Add entry to ACKS.
........
r58570 | georg.brandl | 2007-10-20 12:05:45 -0700 (Sat, 20 Oct 2007) | 2 lines
Clarify -E docs.
........
r58571 | georg.brandl | 2007-10-20 12:08:36 -0700 (Sat, 20 Oct 2007) | 2 lines
Even more clarification.
........
r58572 | andrew.kuchling | 2007-10-20 12:25:37 -0700 (Sat, 20 Oct 2007) | 1 line
Fix protocol name
........
r58573 | andrew.kuchling | 2007-10-20 12:35:18 -0700 (Sat, 20 Oct 2007) | 1 line
Various items
........
r58574 | andrew.kuchling | 2007-10-20 12:39:35 -0700 (Sat, 20 Oct 2007) | 1 line
Use correct header line
........
r58576 | armin.rigo | 2007-10-21 02:14:15 -0700 (Sun, 21 Oct 2007) | 3 lines
Add a crasher for the long-standing issue with closing a file
while another thread uses it.
........
r58577 | georg.brandl | 2007-10-21 03:01:56 -0700 (Sun, 21 Oct 2007) | 2 lines
Remove duplicate crasher.
........
r58578 | georg.brandl | 2007-10-21 03:24:20 -0700 (Sun, 21 Oct 2007) | 2 lines
Unify "byte code" to "bytecode". Also sprinkle :term: markup for it.
........
r58579 | georg.brandl | 2007-10-21 03:32:54 -0700 (Sun, 21 Oct 2007) | 2 lines
Add markup to new function descriptions.
........
r58580 | georg.brandl | 2007-10-21 03:45:46 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for descriptors.
........
r58581 | georg.brandl | 2007-10-21 03:46:24 -0700 (Sun, 21 Oct 2007) | 2 lines
Unify "file-descriptor" to "file descriptor".
........
r58582 | georg.brandl | 2007-10-21 03:52:38 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term: for generators.
........
r58583 | georg.brandl | 2007-10-21 05:10:28 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for iterator.
........
r58584 | georg.brandl | 2007-10-21 05:15:05 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for "new-style class".
........
r58588 | neal.norwitz | 2007-10-21 21:47:54 -0700 (Sun, 21 Oct 2007) | 1 line
Add Chris Monson so he can edit PEPs.
........
r58594 | guido.van.rossum | 2007-10-22 09:27:19 -0700 (Mon, 22 Oct 2007) | 4 lines
Issue #1307, patch by Derek Shockey.
When "MAIL" is received without args, an exception happens instead of
sending a 501 syntax error response.
........
r58598 | travis.oliphant | 2007-10-22 19:40:56 -0700 (Mon, 22 Oct 2007) | 1 line
Add phuang patch from Issue 708374 which adds offset parameter to mmap module.
........
r58601 | neal.norwitz | 2007-10-22 22:44:27 -0700 (Mon, 22 Oct 2007) | 2 lines
Bug #1313, fix typo (wrong variable name) in example.
........
r58609 | georg.brandl | 2007-10-23 11:21:35 -0700 (Tue, 23 Oct 2007) | 2 lines
Update Pygments version from externals.
........
r58618 | guido.van.rossum | 2007-10-23 12:25:41 -0700 (Tue, 23 Oct 2007) | 3 lines
Issue 1307 by Derek Shockey, fox the same bug for RCPT.
Neal: please backport!
........
r58620 | raymond.hettinger | 2007-10-23 13:37:41 -0700 (Tue, 23 Oct 2007) | 1 line
Shorter name for namedtuple()
........
r58621 | andrew.kuchling | 2007-10-23 13:55:47 -0700 (Tue, 23 Oct 2007) | 1 line
Update name
........
r58622 | raymond.hettinger | 2007-10-23 14:23:07 -0700 (Tue, 23 Oct 2007) | 1 line
Fixup news entry
........
r58623 | raymond.hettinger | 2007-10-23 18:28:33 -0700 (Tue, 23 Oct 2007) | 1 line
Optimize sum() for integer and float inputs.
........
r58624 | raymond.hettinger | 2007-10-23 19:05:51 -0700 (Tue, 23 Oct 2007) | 1 line
Fixup error return and add support for intermixed ints and floats/
........
r58628 | vinay.sajip | 2007-10-24 03:47:06 -0700 (Wed, 24 Oct 2007) | 1 line
Bug #1321: Fixed logic error in TimedRotatingFileHandler.__init__()
........
r58641 | facundo.batista | 2007-10-24 12:11:08 -0700 (Wed, 24 Oct 2007) | 4 lines
Issue 1290. CharacterData.__repr__ was constructing a string
in response that keeped having a non-ascii character.
........
r58643 | thomas.heller | 2007-10-24 12:50:45 -0700 (Wed, 24 Oct 2007) | 1 line
Added unittest for calling a function with paramflags (backport from py3k branch).
........
r58645 | matthias.klose | 2007-10-24 13:00:44 -0700 (Wed, 24 Oct 2007) | 2 lines
- Build using system ffi library on arm*-linux*.
........
r58651 | georg.brandl | 2007-10-24 14:40:38 -0700 (Wed, 24 Oct 2007) | 2 lines
Bug #1287: make os.environ.pop() work as expected.
........
r58652 | raymond.hettinger | 2007-10-24 19:26:58 -0700 (Wed, 24 Oct 2007) | 1 line
Missing DECREFs
........
r58653 | matthias.klose | 2007-10-24 23:37:24 -0700 (Wed, 24 Oct 2007) | 2 lines
- Build using system ffi library on arm*-linux*, pass --with-system-ffi to CONFIG_ARGS
........
r58655 | thomas.heller | 2007-10-25 12:47:32 -0700 (Thu, 25 Oct 2007) | 2 lines
ffi_type_longdouble may be already #defined.
See issue 1324.
........
r58656 | kurt.kaiser | 2007-10-25 15:43:45 -0700 (Thu, 25 Oct 2007) | 3 lines
Correct an ancient bug in an unused path by removing that path: register() is
now idempotent.
........
r58660 | kurt.kaiser | 2007-10-25 17:10:09 -0700 (Thu, 25 Oct 2007) | 4 lines
1. Add comments to provide top-level documentation.
2. Refactor to use more descriptive names.
3. Enhance tests in main().
........
r58675 | georg.brandl | 2007-10-26 11:30:41 -0700 (Fri, 26 Oct 2007) | 2 lines
Fix new pop() method on os.environ on ignorecase-platforms.
........
r58696 | neal.norwitz | 2007-10-27 15:32:21 -0700 (Sat, 27 Oct 2007) | 1 line
Update URL for Pygments. 0.8.1 is no longer available
........
r58697 | hyeshik.chang | 2007-10-28 04:19:02 -0700 (Sun, 28 Oct 2007) | 3 lines
- Add support for FreeBSD 8 which is recently forked from FreeBSD 7.
- Regenerate IN module for most recent maintenance tree of FreeBSD 6 and 7.
........
r58698 | hyeshik.chang | 2007-10-28 05:38:09 -0700 (Sun, 28 Oct 2007) | 2 lines
Enable platform-specific tweaks for FreeBSD 8 (exactly same to FreeBSD 7's yet)
........
r58700 | kurt.kaiser | 2007-10-28 12:03:59 -0700 (Sun, 28 Oct 2007) | 2 lines
Add confirmation dialog before printing. Patch 1717170 Tal Einat.
........
r58706 | guido.van.rossum | 2007-10-29 13:52:45 -0700 (Mon, 29 Oct 2007) | 3 lines
Patch 1353 by Jacob Winther.
Add mp4 mapping to mimetypes.py.
........
r58709 | guido.van.rossum | 2007-10-29 15:15:05 -0700 (Mon, 29 Oct 2007) | 6 lines
Backport fixes for the code that decodes octal escapes (and for PyString
also hex escapes) -- this was reaching beyond the end of the input string
buffer, even though it is not supposed to be \0-terminated.
This has no visible effect but is clearly the correct thing to do.
(In 3.0 it had a visible effect after removing ob_sstate from PyString.)
........
r58710 | kurt.kaiser | 2007-10-29 19:38:54 -0700 (Mon, 29 Oct 2007) | 7 lines
check in Tal Einat's update to tabpage.py
Patch 1612746
M configDialog.py
M NEWS.txt
AM tabbedpages.py
........
r58715 | georg.brandl | 2007-10-30 10:51:18 -0700 (Tue, 30 Oct 2007) | 2 lines
Use correct markup.
........
r58716 | georg.brandl | 2007-10-30 10:57:12 -0700 (Tue, 30 Oct 2007) | 2 lines
Make example about hiding None return values at the prompt clearer.
........
r58728 | neal.norwitz | 2007-10-30 23:33:20 -0700 (Tue, 30 Oct 2007) | 1 line
Fix some compiler warnings for signed comparisons on Unix and Windows.
........
r58731 | martin.v.loewis | 2007-10-31 10:19:33 -0700 (Wed, 31 Oct 2007) | 2 lines
Adding Christian Heimes.
........
r58737 | raymond.hettinger | 2007-10-31 14:57:58 -0700 (Wed, 31 Oct 2007) | 1 line
Clarify the reasons why pickle is almost always better than marshal
........
r58739 | raymond.hettinger | 2007-10-31 15:15:49 -0700 (Wed, 31 Oct 2007) | 1 line
Sets are marshalable.
........
2007-11-01 17:32:30 -03:00
|
|
|
|
Merged revisions 58742-58816 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58745 | georg.brandl | 2007-11-01 10:19:33 -0700 (Thu, 01 Nov 2007) | 2 lines
#1364: os.lstat is available on Windows too, as an alias to os.stat.
........
r58750 | christian.heimes | 2007-11-01 12:48:10 -0700 (Thu, 01 Nov 2007) | 1 line
Backport of import tests for bug http://bugs.python.org/issue1293 and bug http://bugs.python.org/issue1342
........
r58751 | christian.heimes | 2007-11-01 13:11:06 -0700 (Thu, 01 Nov 2007) | 1 line
Removed non ASCII text from test as requested by Guido. Sorry :/
........
r58753 | georg.brandl | 2007-11-01 13:37:02 -0700 (Thu, 01 Nov 2007) | 2 lines
Fix markup glitch.
........
r58757 | gregory.p.smith | 2007-11-01 14:08:14 -0700 (Thu, 01 Nov 2007) | 4 lines
Fix bug introduced in revision 58385. Database keys could no longer
have NULL bytes in them. Replace the errant strdup with a
malloc+memcpy. Adds a unit test for the correct behavior.
........
r58758 | gregory.p.smith | 2007-11-01 14:15:36 -0700 (Thu, 01 Nov 2007) | 3 lines
Undo revision 58533 58534 fixes. Those were a workaround for
a problem introduced by 58385.
........
r58759 | gregory.p.smith | 2007-11-01 14:17:47 -0700 (Thu, 01 Nov 2007) | 2 lines
false "fix" undone as correct problem was found and fixed.
........
r58765 | mark.summerfield | 2007-11-02 01:24:59 -0700 (Fri, 02 Nov 2007) | 3 lines
Added more file-handling related cross-references.
........
r58766 | nick.coghlan | 2007-11-02 03:09:12 -0700 (Fri, 02 Nov 2007) | 1 line
Fix for bug 1705170 - contextmanager swallowing StopIteration (2.5 backport candidate)
........
r58784 | thomas.heller | 2007-11-02 12:10:24 -0700 (Fri, 02 Nov 2007) | 4 lines
Issue #1292: On alpha, arm, ppc, and s390 linux systems the
--with-system-ffi configure option defaults to "yes" because the
bundled libffi sources are too old.
........
r58785 | thomas.heller | 2007-11-02 12:11:23 -0700 (Fri, 02 Nov 2007) | 1 line
Enable the full ctypes c_longdouble tests again.
........
r58796 | georg.brandl | 2007-11-02 13:06:17 -0700 (Fri, 02 Nov 2007) | 4 lines
Make "hashable" a glossary entry and clarify docs on __cmp__, __eq__ and __hash__.
I hope the concept of hashability is better understandable now.
Thanks to Tim Hatch for pointing out the flaws here.
........
2007-11-02 20:46:40 -03:00
|
|
|
If *sep* is given, consecutive delimiters are not grouped together and are
|
2007-08-31 07:15:37 -03:00
|
|
|
deemed to delimit empty strings (for example, ``'1,,2'.split(',')`` returns
|
|
|
|
``['1', '', '2']``). The *sep* argument may consist of multiple characters
|
#1370: Finish the merge r58749, log below, by resolving all conflicts in Doc/.
Merged revisions 58221-58741 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58221 | georg.brandl | 2007-09-20 10:57:59 -0700 (Thu, 20 Sep 2007) | 2 lines
Patch #1181: add os.environ.clear() method.
........
r58225 | sean.reifschneider | 2007-09-20 23:33:28 -0700 (Thu, 20 Sep 2007) | 3 lines
Issue1704287: "make install" fails unless you do "make" first. Make
oldsharedmods and sharedmods in "libinstall".
........
r58232 | guido.van.rossum | 2007-09-22 13:18:03 -0700 (Sat, 22 Sep 2007) | 4 lines
Patch # 188 by Philip Jenvey.
Make tell() mark CRLF as a newline.
With unit test.
........
r58242 | georg.brandl | 2007-09-24 10:55:47 -0700 (Mon, 24 Sep 2007) | 2 lines
Fix typo and double word.
........
r58245 | georg.brandl | 2007-09-24 10:59:28 -0700 (Mon, 24 Sep 2007) | 2 lines
#1196: document default radix for int().
........
r58247 | georg.brandl | 2007-09-24 11:08:24 -0700 (Mon, 24 Sep 2007) | 2 lines
#1177: accept 2xx responses for https too, not only http.
........
r58249 | andrew.kuchling | 2007-09-24 16:45:51 -0700 (Mon, 24 Sep 2007) | 1 line
Remove stray odd character; grammar fix
........
r58250 | andrew.kuchling | 2007-09-24 16:46:28 -0700 (Mon, 24 Sep 2007) | 1 line
Typo fix
........
r58251 | andrew.kuchling | 2007-09-24 17:09:42 -0700 (Mon, 24 Sep 2007) | 1 line
Add various items
........
r58268 | vinay.sajip | 2007-09-26 22:34:45 -0700 (Wed, 26 Sep 2007) | 1 line
Change to flush and close logic to fix #1760556.
........
r58269 | vinay.sajip | 2007-09-26 22:38:51 -0700 (Wed, 26 Sep 2007) | 1 line
Change to basicConfig() to fix #1021.
........
r58270 | georg.brandl | 2007-09-26 23:26:58 -0700 (Wed, 26 Sep 2007) | 2 lines
#1208: document match object's boolean value.
........
r58271 | vinay.sajip | 2007-09-26 23:56:13 -0700 (Wed, 26 Sep 2007) | 1 line
Minor date change.
........
r58272 | vinay.sajip | 2007-09-27 00:35:10 -0700 (Thu, 27 Sep 2007) | 1 line
Change to LogRecord.__init__() to fix #1206. Note that archaic use of type(x) == types.DictType is because of keeping 1.5.2 compatibility. While this is much less relevant these days, there probably needs to be a separate commit for removing all archaic constructs at the same time.
........
r58288 | brett.cannon | 2007-09-30 12:45:10 -0700 (Sun, 30 Sep 2007) | 9 lines
tuple.__repr__ did not consider a reference loop as it is not possible from
Python code; but it is possible from C. object.__str__ had the issue of not
expecting a type to doing something within it's tp_str implementation that
could trigger an infinite recursion, but it could in C code.. Both found
thanks to BaseException and how it handles its repr.
Closes issue #1686386. Thanks to Thomas Herve for taking an initial stab at
coming up with a solution.
........
r58289 | brett.cannon | 2007-09-30 13:37:19 -0700 (Sun, 30 Sep 2007) | 3 lines
Fix error introduced by r58288; if a tuple is length 0 return its repr and
don't worry about any self-referring tuples.
........
r58294 | facundo.batista | 2007-10-02 10:01:24 -0700 (Tue, 02 Oct 2007) | 11 lines
Made the various is_* operations return booleans. This was discussed
with Cawlishaw by mail, and he basically confirmed that to these is_*
operations, there's no need to return Decimal(0) and Decimal(1) if
the language supports the False and True booleans.
Also added a few tests for the these functions in extra.decTest, since
they are mostly untested (apart from the doctests).
Thanks Mark Dickinson
........
r58295 | facundo.batista | 2007-10-02 11:21:18 -0700 (Tue, 02 Oct 2007) | 4 lines
Added a class to store the digits of log(10), so that they can be made
available when necessary without recomputing. Thanks Mark Dickinson
........
r58299 | mark.summerfield | 2007-10-03 01:53:21 -0700 (Wed, 03 Oct 2007) | 4 lines
Added note in footnote about string comparisons about
unicodedata.normalize().
........
r58304 | raymond.hettinger | 2007-10-03 14:18:11 -0700 (Wed, 03 Oct 2007) | 1 line
enumerate() is no longer bounded to using sequences shorter than LONG_MAX. The possibility of overflow was sending some newsgroup posters into a tizzy.
........
r58305 | raymond.hettinger | 2007-10-03 17:20:27 -0700 (Wed, 03 Oct 2007) | 1 line
itertools.count() no longer limited to sys.maxint.
........
r58306 | kurt.kaiser | 2007-10-03 18:49:54 -0700 (Wed, 03 Oct 2007) | 3 lines
Assume that the user knows when he wants to end the line; don't insert
something he didn't select or complete.
........
r58307 | kurt.kaiser | 2007-10-03 19:07:50 -0700 (Wed, 03 Oct 2007) | 2 lines
Remove unused theme that was causing a fault in p3k.
........
r58308 | kurt.kaiser | 2007-10-03 19:09:17 -0700 (Wed, 03 Oct 2007) | 2 lines
Clean up EditorWindow close.
........
r58309 | kurt.kaiser | 2007-10-03 19:53:07 -0700 (Wed, 03 Oct 2007) | 7 lines
textView cleanup. Patch 1718043 Tal Einat.
M idlelib/EditorWindow.py
M idlelib/aboutDialog.py
M idlelib/textView.py
M idlelib/NEWS.txt
........
r58310 | kurt.kaiser | 2007-10-03 20:11:12 -0700 (Wed, 03 Oct 2007) | 3 lines
configDialog cleanup. Patch 1730217 Tal Einat.
........
r58311 | neal.norwitz | 2007-10-03 23:00:48 -0700 (Wed, 03 Oct 2007) | 4 lines
Coverity #151: Remove deadcode.
All this code already exists above starting at line 653.
........
r58325 | fred.drake | 2007-10-04 19:46:12 -0700 (Thu, 04 Oct 2007) | 1 line
wrap lines to <80 characters before fixing errors
........
r58326 | raymond.hettinger | 2007-10-04 19:47:07 -0700 (Thu, 04 Oct 2007) | 6 lines
Add __asdict__() to NamedTuple and refine the docs.
Add maxlen support to deque() and fixup docs.
Partially fix __reduce__(). The None as a third arg was no longer supported.
Still needs work on __reduce__() to handle recursive inputs.
........
r58327 | fred.drake | 2007-10-04 19:48:32 -0700 (Thu, 04 Oct 2007) | 3 lines
move descriptions of ac_(in|out)_buffer_size to the right place
http://bugs.python.org/issue1053
........
r58329 | neal.norwitz | 2007-10-04 20:39:17 -0700 (Thu, 04 Oct 2007) | 3 lines
dict could be NULL, so we need to XDECREF.
Fix a compiler warning about passing a PyTypeObject* instead of PyObject*.
........
r58330 | neal.norwitz | 2007-10-04 20:41:19 -0700 (Thu, 04 Oct 2007) | 2 lines
Fix Coverity #158: Check the correct variable.
........
r58332 | neal.norwitz | 2007-10-04 22:01:38 -0700 (Thu, 04 Oct 2007) | 7 lines
Fix Coverity #159.
This code was broken if save() returned a negative number since i contained
a boolean value and then we compared i < 0 which should never be true.
Will backport (assuming it's necessary)
........
r58334 | neal.norwitz | 2007-10-04 22:29:17 -0700 (Thu, 04 Oct 2007) | 1 line
Add a note about fixing some more warnings found by Coverity.
........
r58338 | raymond.hettinger | 2007-10-05 12:07:31 -0700 (Fri, 05 Oct 2007) | 1 line
Restore BEGIN/END THREADS macros which were squashed in the previous checkin
........
r58343 | gregory.p.smith | 2007-10-06 00:48:10 -0700 (Sat, 06 Oct 2007) | 3 lines
Stab in the dark attempt to fix the test_bsddb3 failure on sparc and S-390
ubuntu buildbots.
........
r58344 | gregory.p.smith | 2007-10-06 00:51:59 -0700 (Sat, 06 Oct 2007) | 2 lines
Allows BerkeleyDB 4.6.x >= 4.6.21 for the bsddb module.
........
r58348 | gregory.p.smith | 2007-10-06 08:47:37 -0700 (Sat, 06 Oct 2007) | 3 lines
Use the host the author likely meant in the first place. pop.gmail.com is
reliable. gmail.org is someones personal domain.
........
r58351 | neal.norwitz | 2007-10-06 12:16:28 -0700 (Sat, 06 Oct 2007) | 3 lines
Ensure that this test will pass even if another test left an unwritable TESTFN.
Also use the safe unlink in test_support instead of rolling our own here.
........
r58368 | georg.brandl | 2007-10-08 00:50:24 -0700 (Mon, 08 Oct 2007) | 3 lines
#1123: fix the docs for the str.split(None, sep) case.
Also expand a few other methods' docs, which had more info in the deprecated string module docs.
........
r58369 | georg.brandl | 2007-10-08 01:06:05 -0700 (Mon, 08 Oct 2007) | 2 lines
Update docstring of sched, also remove an unused assignment.
........
r58370 | raymond.hettinger | 2007-10-08 02:14:28 -0700 (Mon, 08 Oct 2007) | 5 lines
Add comments to NamedTuple code.
Let the field spec be either a string or a non-string sequence (suggested by Martin Blais with use cases).
Improve the error message in the case of a SyntaxError (caused by a duplicate field name).
........
r58371 | raymond.hettinger | 2007-10-08 02:56:29 -0700 (Mon, 08 Oct 2007) | 1 line
Missed a line in the docs
........
r58372 | raymond.hettinger | 2007-10-08 03:11:51 -0700 (Mon, 08 Oct 2007) | 1 line
Better variable names
........
r58376 | georg.brandl | 2007-10-08 07:12:47 -0700 (Mon, 08 Oct 2007) | 3 lines
#1199: docs for tp_as_{number,sequence,mapping}, by Amaury Forgeot d'Arc.
No need to merge this to py3k!
........
r58380 | raymond.hettinger | 2007-10-08 14:26:58 -0700 (Mon, 08 Oct 2007) | 1 line
Eliminate camelcase function name
........
r58381 | andrew.kuchling | 2007-10-08 16:23:03 -0700 (Mon, 08 Oct 2007) | 1 line
Eliminate camelcase function name
........
r58382 | raymond.hettinger | 2007-10-08 18:36:23 -0700 (Mon, 08 Oct 2007) | 1 line
Make the error messages more specific
........
r58384 | gregory.p.smith | 2007-10-08 23:02:21 -0700 (Mon, 08 Oct 2007) | 10 lines
Splits Modules/_bsddb.c up into bsddb.h and _bsddb.c and adds a C API
object available as bsddb.db.api. This is based on the patch submitted
by Duncan Grisby here:
http://sourceforge.net/tracker/index.php?func=detail&aid=1551895&group_id=13900&atid=313900
See this thread for additional info:
http://sourceforge.net/mailarchive/forum.php?thread_name=E1GAVDK-0002rk-Iw%40apasphere.com&forum_name=pybsddb-users
It also cleans up the code a little by removing some ifdef/endifs for
python prior to 2.1 and for unsupported Berkeley DB <= 3.2.
........
r58385 | gregory.p.smith | 2007-10-08 23:50:43 -0700 (Mon, 08 Oct 2007) | 5 lines
Fix a double free when positioning a database cursor to a non-existant
string key (and probably a few other situations with string keys).
This was reported with a patch as pybsddb sourceforge bug 1708868 by
jjjhhhlll at gmail.
........
r58386 | gregory.p.smith | 2007-10-09 00:19:11 -0700 (Tue, 09 Oct 2007) | 3 lines
Use the highest cPickle protocol in bsddb.dbshelve. This comes from
sourceforge pybsddb patch 1551443 by w_barnes.
........
r58394 | gregory.p.smith | 2007-10-09 11:26:02 -0700 (Tue, 09 Oct 2007) | 2 lines
remove another sleepycat reference
........
r58396 | kurt.kaiser | 2007-10-09 12:31:30 -0700 (Tue, 09 Oct 2007) | 3 lines
Allow interrupt only when executing user code in subprocess
Patch 1225 Tal Einat modified from IDLE-Spoon.
........
r58399 | brett.cannon | 2007-10-09 17:07:50 -0700 (Tue, 09 Oct 2007) | 5 lines
Remove file-level typedefs that were inconsistently used throughout the file.
Just move over to the public API names.
Closes issue1238.
........
r58401 | raymond.hettinger | 2007-10-09 17:26:46 -0700 (Tue, 09 Oct 2007) | 1 line
Accept Jim Jewett's api suggestion to use None instead of -1 to indicate unbounded deques.
........
r58403 | kurt.kaiser | 2007-10-09 17:55:40 -0700 (Tue, 09 Oct 2007) | 2 lines
Allow cursor color change w/o restart. Patch 1725576 Tal Einat.
........
r58404 | kurt.kaiser | 2007-10-09 18:06:47 -0700 (Tue, 09 Oct 2007) | 2 lines
show paste if > 80 columns. Patch 1659326 Tal Einat.
........
r58415 | thomas.heller | 2007-10-11 12:51:32 -0700 (Thu, 11 Oct 2007) | 5 lines
On OS X, use os.uname() instead of gestalt.sysv(...) to get the
operating system version. This allows to use ctypes when Python
was configured with --disable-toolbox-glue.
........
r58419 | neal.norwitz | 2007-10-11 20:01:01 -0700 (Thu, 11 Oct 2007) | 1 line
Get rid of warning about not being able to create an existing directory.
........
r58420 | neal.norwitz | 2007-10-11 20:01:30 -0700 (Thu, 11 Oct 2007) | 1 line
Get rid of warnings on a bunch of platforms by using a proper prototype.
........
r58421 | neal.norwitz | 2007-10-11 20:01:54 -0700 (Thu, 11 Oct 2007) | 4 lines
Get rid of compiler warning about retval being used (returned) without
being initialized. (gcc warning and Coverity 202)
........
r58422 | neal.norwitz | 2007-10-11 20:03:23 -0700 (Thu, 11 Oct 2007) | 1 line
Fix Coverity 168: Close the file before returning (exiting).
........
r58423 | neal.norwitz | 2007-10-11 20:04:18 -0700 (Thu, 11 Oct 2007) | 4 lines
Fix Coverity 180: Don't overallocate. We don't need structs, but pointers.
Also fix a memory leak.
........
r58424 | neal.norwitz | 2007-10-11 20:05:19 -0700 (Thu, 11 Oct 2007) | 5 lines
Fix Coverity 185-186: If the passed in FILE is NULL, uninitialized memory
would be accessed.
Will backport.
........
r58425 | neal.norwitz | 2007-10-11 20:52:34 -0700 (Thu, 11 Oct 2007) | 1 line
Get this module to compile with bsddb versions prior to 4.3
........
r58430 | martin.v.loewis | 2007-10-12 01:56:52 -0700 (Fri, 12 Oct 2007) | 3 lines
Bug #1216: Restore support for Visual Studio 2002.
Will backport to 2.5.
........
r58433 | raymond.hettinger | 2007-10-12 10:53:11 -0700 (Fri, 12 Oct 2007) | 1 line
Fix test of count.__repr__() to ignore the 'L' if the count is a long
........
r58434 | gregory.p.smith | 2007-10-12 11:44:06 -0700 (Fri, 12 Oct 2007) | 4 lines
Fixes http://bugs.python.org/issue1233 - bsddb.dbshelve.DBShelf.append
was useless due to inverted logic. Also adds a test case for RECNO dbs
to test_dbshelve.
........
r58445 | georg.brandl | 2007-10-13 06:20:03 -0700 (Sat, 13 Oct 2007) | 2 lines
Fix email example.
........
r58450 | gregory.p.smith | 2007-10-13 16:02:05 -0700 (Sat, 13 Oct 2007) | 2 lines
Fix an uncollectable reference leak in bsddb.db.DBShelf.append
........
r58453 | neal.norwitz | 2007-10-13 17:18:40 -0700 (Sat, 13 Oct 2007) | 8 lines
Let the O/S supply a port if none of the default ports can be used.
This should make the tests more robust at the expense of allowing
tests to be sloppier by not requiring them to cleanup after themselves.
(It will legitamitely help when running two test suites simultaneously
or if another process is already using one of the predefined ports.)
Also simplifies (slightLy) the exception handling elsewhere.
........
r58459 | neal.norwitz | 2007-10-14 11:30:21 -0700 (Sun, 14 Oct 2007) | 2 lines
Don't raise a string exception, they don't work anymore.
........
r58460 | neal.norwitz | 2007-10-14 11:40:37 -0700 (Sun, 14 Oct 2007) | 1 line
Use unittest for assertions
........
r58468 | armin.rigo | 2007-10-15 00:48:35 -0700 (Mon, 15 Oct 2007) | 2 lines
test_bigbits was not testing what it seemed to.
........
r58471 | guido.van.rossum | 2007-10-15 08:54:11 -0700 (Mon, 15 Oct 2007) | 3 lines
Change a PyErr_Print() into a PyErr_Clear(),
per discussion in issue 1031213.
........
r58500 | raymond.hettinger | 2007-10-16 12:18:30 -0700 (Tue, 16 Oct 2007) | 1 line
Improve error messages
........
r58506 | raymond.hettinger | 2007-10-16 14:28:32 -0700 (Tue, 16 Oct 2007) | 1 line
More docs, error messages, and tests
........
r58507 | andrew.kuchling | 2007-10-16 15:58:03 -0700 (Tue, 16 Oct 2007) | 1 line
Add items
........
r58508 | brett.cannon | 2007-10-16 16:24:06 -0700 (Tue, 16 Oct 2007) | 3 lines
Remove ``:const:`` notation on None in parameter list. Since the markup is not
rendered for parameters it just showed up as ``:const:`None` `` in the output.
........
r58509 | brett.cannon | 2007-10-16 16:26:45 -0700 (Tue, 16 Oct 2007) | 3 lines
Re-order some functions whose parameters differ between PyObject and const char
* so that they are next to each other.
........
r58522 | armin.rigo | 2007-10-17 11:46:37 -0700 (Wed, 17 Oct 2007) | 5 lines
Fix the overflow checking of list_repeat.
Introduce overflow checking into list_inplace_repeat.
Backport candidate, possibly.
........
r58530 | facundo.batista | 2007-10-17 20:16:03 -0700 (Wed, 17 Oct 2007) | 7 lines
Issue #1580738. When HTTPConnection reads the whole stream with read(),
it closes itself. When the stream is read in several calls to read(n),
it should behave in the same way if HTTPConnection knows where the end
of the stream is (through self.length). Added a test case for this
behaviour.
........
r58531 | facundo.batista | 2007-10-17 20:44:48 -0700 (Wed, 17 Oct 2007) | 3 lines
Issue 1289, just a typo.
........
r58532 | gregory.p.smith | 2007-10-18 00:56:54 -0700 (Thu, 18 Oct 2007) | 4 lines
cleanup test_dbtables to use mkdtemp. cleanup dbtables to pass txn as a
keyword argument whenever possible to avoid bugs and confusion. (dbtables.py
line 447 self.db.get using txn as a non-keyword was an actual bug due to this)
........
r58533 | gregory.p.smith | 2007-10-18 01:34:20 -0700 (Thu, 18 Oct 2007) | 4 lines
Fix a weird bug in dbtables: if it chose a random rowid string that contained
NULL bytes it would cause the database all sorts of problems in the future
leading to very strange random failures and corrupt dbtables.bsdTableDb dbs.
........
r58534 | gregory.p.smith | 2007-10-18 09:32:02 -0700 (Thu, 18 Oct 2007) | 3 lines
A cleaner fix than the one committed last night. Generate random rowids that
do not contain null bytes.
........
r58537 | gregory.p.smith | 2007-10-18 10:17:57 -0700 (Thu, 18 Oct 2007) | 2 lines
mention bsddb fixes.
........
r58538 | raymond.hettinger | 2007-10-18 14:13:06 -0700 (Thu, 18 Oct 2007) | 1 line
Remove useless warning
........
r58539 | gregory.p.smith | 2007-10-19 00:31:20 -0700 (Fri, 19 Oct 2007) | 2 lines
squelch the warning that this test is supposed to trigger.
........
r58542 | georg.brandl | 2007-10-19 05:32:39 -0700 (Fri, 19 Oct 2007) | 2 lines
Clarify wording for apply().
........
r58544 | mark.summerfield | 2007-10-19 05:48:17 -0700 (Fri, 19 Oct 2007) | 3 lines
Added a cross-ref to each other.
........
r58545 | georg.brandl | 2007-10-19 10:38:49 -0700 (Fri, 19 Oct 2007) | 2 lines
#1284: "S" means "seen", not unread.
........
r58548 | thomas.heller | 2007-10-19 11:11:41 -0700 (Fri, 19 Oct 2007) | 4 lines
Fix ctypes on 32-bit systems when Python is configured --with-system-ffi.
See also https://bugs.launchpad.net/bugs/72505.
Ported from release25-maint branch.
........
r58550 | facundo.batista | 2007-10-19 12:25:57 -0700 (Fri, 19 Oct 2007) | 8 lines
The constructor from tuple was way too permissive: it allowed bad
coefficient numbers, floats in the sign, and other details that
generated directly the wrong number in the best case, or triggered
misfunctionality in the alorithms.
Test cases added for these issues. Thanks Mark Dickinson.
........
r58559 | georg.brandl | 2007-10-20 06:22:53 -0700 (Sat, 20 Oct 2007) | 2 lines
Fix code being interpreted as a target.
........
r58561 | georg.brandl | 2007-10-20 06:36:24 -0700 (Sat, 20 Oct 2007) | 2 lines
Document new "cmdoption" directive.
........
r58562 | georg.brandl | 2007-10-20 08:21:22 -0700 (Sat, 20 Oct 2007) | 2 lines
Make a path more Unix-standardy.
........
r58564 | georg.brandl | 2007-10-20 10:51:39 -0700 (Sat, 20 Oct 2007) | 2 lines
Document new directive "envvar".
........
r58567 | georg.brandl | 2007-10-20 11:08:14 -0700 (Sat, 20 Oct 2007) | 6 lines
* Add new toplevel chapter, "Using Python." (how to install,
configure and setup python on different platforms -- at least
in theory.)
* Move the Python on Mac docs in that chapter.
* Add a new chapter about the command line invocation, by stargaming.
........
r58568 | georg.brandl | 2007-10-20 11:33:20 -0700 (Sat, 20 Oct 2007) | 2 lines
Change title, for now.
........
r58569 | georg.brandl | 2007-10-20 11:39:25 -0700 (Sat, 20 Oct 2007) | 2 lines
Add entry to ACKS.
........
r58570 | georg.brandl | 2007-10-20 12:05:45 -0700 (Sat, 20 Oct 2007) | 2 lines
Clarify -E docs.
........
r58571 | georg.brandl | 2007-10-20 12:08:36 -0700 (Sat, 20 Oct 2007) | 2 lines
Even more clarification.
........
r58572 | andrew.kuchling | 2007-10-20 12:25:37 -0700 (Sat, 20 Oct 2007) | 1 line
Fix protocol name
........
r58573 | andrew.kuchling | 2007-10-20 12:35:18 -0700 (Sat, 20 Oct 2007) | 1 line
Various items
........
r58574 | andrew.kuchling | 2007-10-20 12:39:35 -0700 (Sat, 20 Oct 2007) | 1 line
Use correct header line
........
r58576 | armin.rigo | 2007-10-21 02:14:15 -0700 (Sun, 21 Oct 2007) | 3 lines
Add a crasher for the long-standing issue with closing a file
while another thread uses it.
........
r58577 | georg.brandl | 2007-10-21 03:01:56 -0700 (Sun, 21 Oct 2007) | 2 lines
Remove duplicate crasher.
........
r58578 | georg.brandl | 2007-10-21 03:24:20 -0700 (Sun, 21 Oct 2007) | 2 lines
Unify "byte code" to "bytecode". Also sprinkle :term: markup for it.
........
r58579 | georg.brandl | 2007-10-21 03:32:54 -0700 (Sun, 21 Oct 2007) | 2 lines
Add markup to new function descriptions.
........
r58580 | georg.brandl | 2007-10-21 03:45:46 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for descriptors.
........
r58581 | georg.brandl | 2007-10-21 03:46:24 -0700 (Sun, 21 Oct 2007) | 2 lines
Unify "file-descriptor" to "file descriptor".
........
r58582 | georg.brandl | 2007-10-21 03:52:38 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term: for generators.
........
r58583 | georg.brandl | 2007-10-21 05:10:28 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for iterator.
........
r58584 | georg.brandl | 2007-10-21 05:15:05 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for "new-style class".
........
r58588 | neal.norwitz | 2007-10-21 21:47:54 -0700 (Sun, 21 Oct 2007) | 1 line
Add Chris Monson so he can edit PEPs.
........
r58594 | guido.van.rossum | 2007-10-22 09:27:19 -0700 (Mon, 22 Oct 2007) | 4 lines
Issue #1307, patch by Derek Shockey.
When "MAIL" is received without args, an exception happens instead of
sending a 501 syntax error response.
........
r58598 | travis.oliphant | 2007-10-22 19:40:56 -0700 (Mon, 22 Oct 2007) | 1 line
Add phuang patch from Issue 708374 which adds offset parameter to mmap module.
........
r58601 | neal.norwitz | 2007-10-22 22:44:27 -0700 (Mon, 22 Oct 2007) | 2 lines
Bug #1313, fix typo (wrong variable name) in example.
........
r58609 | georg.brandl | 2007-10-23 11:21:35 -0700 (Tue, 23 Oct 2007) | 2 lines
Update Pygments version from externals.
........
r58618 | guido.van.rossum | 2007-10-23 12:25:41 -0700 (Tue, 23 Oct 2007) | 3 lines
Issue 1307 by Derek Shockey, fox the same bug for RCPT.
Neal: please backport!
........
r58620 | raymond.hettinger | 2007-10-23 13:37:41 -0700 (Tue, 23 Oct 2007) | 1 line
Shorter name for namedtuple()
........
r58621 | andrew.kuchling | 2007-10-23 13:55:47 -0700 (Tue, 23 Oct 2007) | 1 line
Update name
........
r58622 | raymond.hettinger | 2007-10-23 14:23:07 -0700 (Tue, 23 Oct 2007) | 1 line
Fixup news entry
........
r58623 | raymond.hettinger | 2007-10-23 18:28:33 -0700 (Tue, 23 Oct 2007) | 1 line
Optimize sum() for integer and float inputs.
........
r58624 | raymond.hettinger | 2007-10-23 19:05:51 -0700 (Tue, 23 Oct 2007) | 1 line
Fixup error return and add support for intermixed ints and floats/
........
r58628 | vinay.sajip | 2007-10-24 03:47:06 -0700 (Wed, 24 Oct 2007) | 1 line
Bug #1321: Fixed logic error in TimedRotatingFileHandler.__init__()
........
r58641 | facundo.batista | 2007-10-24 12:11:08 -0700 (Wed, 24 Oct 2007) | 4 lines
Issue 1290. CharacterData.__repr__ was constructing a string
in response that keeped having a non-ascii character.
........
r58643 | thomas.heller | 2007-10-24 12:50:45 -0700 (Wed, 24 Oct 2007) | 1 line
Added unittest for calling a function with paramflags (backport from py3k branch).
........
r58645 | matthias.klose | 2007-10-24 13:00:44 -0700 (Wed, 24 Oct 2007) | 2 lines
- Build using system ffi library on arm*-linux*.
........
r58651 | georg.brandl | 2007-10-24 14:40:38 -0700 (Wed, 24 Oct 2007) | 2 lines
Bug #1287: make os.environ.pop() work as expected.
........
r58652 | raymond.hettinger | 2007-10-24 19:26:58 -0700 (Wed, 24 Oct 2007) | 1 line
Missing DECREFs
........
r58653 | matthias.klose | 2007-10-24 23:37:24 -0700 (Wed, 24 Oct 2007) | 2 lines
- Build using system ffi library on arm*-linux*, pass --with-system-ffi to CONFIG_ARGS
........
r58655 | thomas.heller | 2007-10-25 12:47:32 -0700 (Thu, 25 Oct 2007) | 2 lines
ffi_type_longdouble may be already #defined.
See issue 1324.
........
r58656 | kurt.kaiser | 2007-10-25 15:43:45 -0700 (Thu, 25 Oct 2007) | 3 lines
Correct an ancient bug in an unused path by removing that path: register() is
now idempotent.
........
r58660 | kurt.kaiser | 2007-10-25 17:10:09 -0700 (Thu, 25 Oct 2007) | 4 lines
1. Add comments to provide top-level documentation.
2. Refactor to use more descriptive names.
3. Enhance tests in main().
........
r58675 | georg.brandl | 2007-10-26 11:30:41 -0700 (Fri, 26 Oct 2007) | 2 lines
Fix new pop() method on os.environ on ignorecase-platforms.
........
r58696 | neal.norwitz | 2007-10-27 15:32:21 -0700 (Sat, 27 Oct 2007) | 1 line
Update URL for Pygments. 0.8.1 is no longer available
........
r58697 | hyeshik.chang | 2007-10-28 04:19:02 -0700 (Sun, 28 Oct 2007) | 3 lines
- Add support for FreeBSD 8 which is recently forked from FreeBSD 7.
- Regenerate IN module for most recent maintenance tree of FreeBSD 6 and 7.
........
r58698 | hyeshik.chang | 2007-10-28 05:38:09 -0700 (Sun, 28 Oct 2007) | 2 lines
Enable platform-specific tweaks for FreeBSD 8 (exactly same to FreeBSD 7's yet)
........
r58700 | kurt.kaiser | 2007-10-28 12:03:59 -0700 (Sun, 28 Oct 2007) | 2 lines
Add confirmation dialog before printing. Patch 1717170 Tal Einat.
........
r58706 | guido.van.rossum | 2007-10-29 13:52:45 -0700 (Mon, 29 Oct 2007) | 3 lines
Patch 1353 by Jacob Winther.
Add mp4 mapping to mimetypes.py.
........
r58709 | guido.van.rossum | 2007-10-29 15:15:05 -0700 (Mon, 29 Oct 2007) | 6 lines
Backport fixes for the code that decodes octal escapes (and for PyString
also hex escapes) -- this was reaching beyond the end of the input string
buffer, even though it is not supposed to be \0-terminated.
This has no visible effect but is clearly the correct thing to do.
(In 3.0 it had a visible effect after removing ob_sstate from PyString.)
........
r58710 | kurt.kaiser | 2007-10-29 19:38:54 -0700 (Mon, 29 Oct 2007) | 7 lines
check in Tal Einat's update to tabpage.py
Patch 1612746
M configDialog.py
M NEWS.txt
AM tabbedpages.py
........
r58715 | georg.brandl | 2007-10-30 10:51:18 -0700 (Tue, 30 Oct 2007) | 2 lines
Use correct markup.
........
r58716 | georg.brandl | 2007-10-30 10:57:12 -0700 (Tue, 30 Oct 2007) | 2 lines
Make example about hiding None return values at the prompt clearer.
........
r58728 | neal.norwitz | 2007-10-30 23:33:20 -0700 (Tue, 30 Oct 2007) | 1 line
Fix some compiler warnings for signed comparisons on Unix and Windows.
........
r58731 | martin.v.loewis | 2007-10-31 10:19:33 -0700 (Wed, 31 Oct 2007) | 2 lines
Adding Christian Heimes.
........
r58737 | raymond.hettinger | 2007-10-31 14:57:58 -0700 (Wed, 31 Oct 2007) | 1 line
Clarify the reasons why pickle is almost always better than marshal
........
r58739 | raymond.hettinger | 2007-10-31 15:15:49 -0700 (Wed, 31 Oct 2007) | 1 line
Sets are marshalable.
........
2007-11-01 17:32:30 -03:00
|
|
|
(for example, ``'1<>2<>3'.split('<>')`` returns ``['1', '2', '3']``).
|
2007-08-31 07:15:37 -03:00
|
|
|
Splitting an empty string with a specified separator returns ``['']``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2014-08-09 03:14:04 -03:00
|
|
|
For example::
|
|
|
|
|
|
|
|
>>> '1,2,3'.split(',')
|
|
|
|
['1', '2', '3']
|
|
|
|
>>> '1,2,3'.split(',', maxsplit=1)
|
2014-09-22 23:43:50 -03:00
|
|
|
['1', '2,3']
|
2014-08-09 03:14:04 -03:00
|
|
|
>>> '1,2,,3,'.split(',')
|
|
|
|
['1', '2', '', '3', '']
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
If *sep* is not specified or is ``None``, a different splitting algorithm is
|
#1370: Finish the merge r58749, log below, by resolving all conflicts in Doc/.
Merged revisions 58221-58741 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58221 | georg.brandl | 2007-09-20 10:57:59 -0700 (Thu, 20 Sep 2007) | 2 lines
Patch #1181: add os.environ.clear() method.
........
r58225 | sean.reifschneider | 2007-09-20 23:33:28 -0700 (Thu, 20 Sep 2007) | 3 lines
Issue1704287: "make install" fails unless you do "make" first. Make
oldsharedmods and sharedmods in "libinstall".
........
r58232 | guido.van.rossum | 2007-09-22 13:18:03 -0700 (Sat, 22 Sep 2007) | 4 lines
Patch # 188 by Philip Jenvey.
Make tell() mark CRLF as a newline.
With unit test.
........
r58242 | georg.brandl | 2007-09-24 10:55:47 -0700 (Mon, 24 Sep 2007) | 2 lines
Fix typo and double word.
........
r58245 | georg.brandl | 2007-09-24 10:59:28 -0700 (Mon, 24 Sep 2007) | 2 lines
#1196: document default radix for int().
........
r58247 | georg.brandl | 2007-09-24 11:08:24 -0700 (Mon, 24 Sep 2007) | 2 lines
#1177: accept 2xx responses for https too, not only http.
........
r58249 | andrew.kuchling | 2007-09-24 16:45:51 -0700 (Mon, 24 Sep 2007) | 1 line
Remove stray odd character; grammar fix
........
r58250 | andrew.kuchling | 2007-09-24 16:46:28 -0700 (Mon, 24 Sep 2007) | 1 line
Typo fix
........
r58251 | andrew.kuchling | 2007-09-24 17:09:42 -0700 (Mon, 24 Sep 2007) | 1 line
Add various items
........
r58268 | vinay.sajip | 2007-09-26 22:34:45 -0700 (Wed, 26 Sep 2007) | 1 line
Change to flush and close logic to fix #1760556.
........
r58269 | vinay.sajip | 2007-09-26 22:38:51 -0700 (Wed, 26 Sep 2007) | 1 line
Change to basicConfig() to fix #1021.
........
r58270 | georg.brandl | 2007-09-26 23:26:58 -0700 (Wed, 26 Sep 2007) | 2 lines
#1208: document match object's boolean value.
........
r58271 | vinay.sajip | 2007-09-26 23:56:13 -0700 (Wed, 26 Sep 2007) | 1 line
Minor date change.
........
r58272 | vinay.sajip | 2007-09-27 00:35:10 -0700 (Thu, 27 Sep 2007) | 1 line
Change to LogRecord.__init__() to fix #1206. Note that archaic use of type(x) == types.DictType is because of keeping 1.5.2 compatibility. While this is much less relevant these days, there probably needs to be a separate commit for removing all archaic constructs at the same time.
........
r58288 | brett.cannon | 2007-09-30 12:45:10 -0700 (Sun, 30 Sep 2007) | 9 lines
tuple.__repr__ did not consider a reference loop as it is not possible from
Python code; but it is possible from C. object.__str__ had the issue of not
expecting a type to doing something within it's tp_str implementation that
could trigger an infinite recursion, but it could in C code.. Both found
thanks to BaseException and how it handles its repr.
Closes issue #1686386. Thanks to Thomas Herve for taking an initial stab at
coming up with a solution.
........
r58289 | brett.cannon | 2007-09-30 13:37:19 -0700 (Sun, 30 Sep 2007) | 3 lines
Fix error introduced by r58288; if a tuple is length 0 return its repr and
don't worry about any self-referring tuples.
........
r58294 | facundo.batista | 2007-10-02 10:01:24 -0700 (Tue, 02 Oct 2007) | 11 lines
Made the various is_* operations return booleans. This was discussed
with Cawlishaw by mail, and he basically confirmed that to these is_*
operations, there's no need to return Decimal(0) and Decimal(1) if
the language supports the False and True booleans.
Also added a few tests for the these functions in extra.decTest, since
they are mostly untested (apart from the doctests).
Thanks Mark Dickinson
........
r58295 | facundo.batista | 2007-10-02 11:21:18 -0700 (Tue, 02 Oct 2007) | 4 lines
Added a class to store the digits of log(10), so that they can be made
available when necessary without recomputing. Thanks Mark Dickinson
........
r58299 | mark.summerfield | 2007-10-03 01:53:21 -0700 (Wed, 03 Oct 2007) | 4 lines
Added note in footnote about string comparisons about
unicodedata.normalize().
........
r58304 | raymond.hettinger | 2007-10-03 14:18:11 -0700 (Wed, 03 Oct 2007) | 1 line
enumerate() is no longer bounded to using sequences shorter than LONG_MAX. The possibility of overflow was sending some newsgroup posters into a tizzy.
........
r58305 | raymond.hettinger | 2007-10-03 17:20:27 -0700 (Wed, 03 Oct 2007) | 1 line
itertools.count() no longer limited to sys.maxint.
........
r58306 | kurt.kaiser | 2007-10-03 18:49:54 -0700 (Wed, 03 Oct 2007) | 3 lines
Assume that the user knows when he wants to end the line; don't insert
something he didn't select or complete.
........
r58307 | kurt.kaiser | 2007-10-03 19:07:50 -0700 (Wed, 03 Oct 2007) | 2 lines
Remove unused theme that was causing a fault in p3k.
........
r58308 | kurt.kaiser | 2007-10-03 19:09:17 -0700 (Wed, 03 Oct 2007) | 2 lines
Clean up EditorWindow close.
........
r58309 | kurt.kaiser | 2007-10-03 19:53:07 -0700 (Wed, 03 Oct 2007) | 7 lines
textView cleanup. Patch 1718043 Tal Einat.
M idlelib/EditorWindow.py
M idlelib/aboutDialog.py
M idlelib/textView.py
M idlelib/NEWS.txt
........
r58310 | kurt.kaiser | 2007-10-03 20:11:12 -0700 (Wed, 03 Oct 2007) | 3 lines
configDialog cleanup. Patch 1730217 Tal Einat.
........
r58311 | neal.norwitz | 2007-10-03 23:00:48 -0700 (Wed, 03 Oct 2007) | 4 lines
Coverity #151: Remove deadcode.
All this code already exists above starting at line 653.
........
r58325 | fred.drake | 2007-10-04 19:46:12 -0700 (Thu, 04 Oct 2007) | 1 line
wrap lines to <80 characters before fixing errors
........
r58326 | raymond.hettinger | 2007-10-04 19:47:07 -0700 (Thu, 04 Oct 2007) | 6 lines
Add __asdict__() to NamedTuple and refine the docs.
Add maxlen support to deque() and fixup docs.
Partially fix __reduce__(). The None as a third arg was no longer supported.
Still needs work on __reduce__() to handle recursive inputs.
........
r58327 | fred.drake | 2007-10-04 19:48:32 -0700 (Thu, 04 Oct 2007) | 3 lines
move descriptions of ac_(in|out)_buffer_size to the right place
http://bugs.python.org/issue1053
........
r58329 | neal.norwitz | 2007-10-04 20:39:17 -0700 (Thu, 04 Oct 2007) | 3 lines
dict could be NULL, so we need to XDECREF.
Fix a compiler warning about passing a PyTypeObject* instead of PyObject*.
........
r58330 | neal.norwitz | 2007-10-04 20:41:19 -0700 (Thu, 04 Oct 2007) | 2 lines
Fix Coverity #158: Check the correct variable.
........
r58332 | neal.norwitz | 2007-10-04 22:01:38 -0700 (Thu, 04 Oct 2007) | 7 lines
Fix Coverity #159.
This code was broken if save() returned a negative number since i contained
a boolean value and then we compared i < 0 which should never be true.
Will backport (assuming it's necessary)
........
r58334 | neal.norwitz | 2007-10-04 22:29:17 -0700 (Thu, 04 Oct 2007) | 1 line
Add a note about fixing some more warnings found by Coverity.
........
r58338 | raymond.hettinger | 2007-10-05 12:07:31 -0700 (Fri, 05 Oct 2007) | 1 line
Restore BEGIN/END THREADS macros which were squashed in the previous checkin
........
r58343 | gregory.p.smith | 2007-10-06 00:48:10 -0700 (Sat, 06 Oct 2007) | 3 lines
Stab in the dark attempt to fix the test_bsddb3 failure on sparc and S-390
ubuntu buildbots.
........
r58344 | gregory.p.smith | 2007-10-06 00:51:59 -0700 (Sat, 06 Oct 2007) | 2 lines
Allows BerkeleyDB 4.6.x >= 4.6.21 for the bsddb module.
........
r58348 | gregory.p.smith | 2007-10-06 08:47:37 -0700 (Sat, 06 Oct 2007) | 3 lines
Use the host the author likely meant in the first place. pop.gmail.com is
reliable. gmail.org is someones personal domain.
........
r58351 | neal.norwitz | 2007-10-06 12:16:28 -0700 (Sat, 06 Oct 2007) | 3 lines
Ensure that this test will pass even if another test left an unwritable TESTFN.
Also use the safe unlink in test_support instead of rolling our own here.
........
r58368 | georg.brandl | 2007-10-08 00:50:24 -0700 (Mon, 08 Oct 2007) | 3 lines
#1123: fix the docs for the str.split(None, sep) case.
Also expand a few other methods' docs, which had more info in the deprecated string module docs.
........
r58369 | georg.brandl | 2007-10-08 01:06:05 -0700 (Mon, 08 Oct 2007) | 2 lines
Update docstring of sched, also remove an unused assignment.
........
r58370 | raymond.hettinger | 2007-10-08 02:14:28 -0700 (Mon, 08 Oct 2007) | 5 lines
Add comments to NamedTuple code.
Let the field spec be either a string or a non-string sequence (suggested by Martin Blais with use cases).
Improve the error message in the case of a SyntaxError (caused by a duplicate field name).
........
r58371 | raymond.hettinger | 2007-10-08 02:56:29 -0700 (Mon, 08 Oct 2007) | 1 line
Missed a line in the docs
........
r58372 | raymond.hettinger | 2007-10-08 03:11:51 -0700 (Mon, 08 Oct 2007) | 1 line
Better variable names
........
r58376 | georg.brandl | 2007-10-08 07:12:47 -0700 (Mon, 08 Oct 2007) | 3 lines
#1199: docs for tp_as_{number,sequence,mapping}, by Amaury Forgeot d'Arc.
No need to merge this to py3k!
........
r58380 | raymond.hettinger | 2007-10-08 14:26:58 -0700 (Mon, 08 Oct 2007) | 1 line
Eliminate camelcase function name
........
r58381 | andrew.kuchling | 2007-10-08 16:23:03 -0700 (Mon, 08 Oct 2007) | 1 line
Eliminate camelcase function name
........
r58382 | raymond.hettinger | 2007-10-08 18:36:23 -0700 (Mon, 08 Oct 2007) | 1 line
Make the error messages more specific
........
r58384 | gregory.p.smith | 2007-10-08 23:02:21 -0700 (Mon, 08 Oct 2007) | 10 lines
Splits Modules/_bsddb.c up into bsddb.h and _bsddb.c and adds a C API
object available as bsddb.db.api. This is based on the patch submitted
by Duncan Grisby here:
http://sourceforge.net/tracker/index.php?func=detail&aid=1551895&group_id=13900&atid=313900
See this thread for additional info:
http://sourceforge.net/mailarchive/forum.php?thread_name=E1GAVDK-0002rk-Iw%40apasphere.com&forum_name=pybsddb-users
It also cleans up the code a little by removing some ifdef/endifs for
python prior to 2.1 and for unsupported Berkeley DB <= 3.2.
........
r58385 | gregory.p.smith | 2007-10-08 23:50:43 -0700 (Mon, 08 Oct 2007) | 5 lines
Fix a double free when positioning a database cursor to a non-existant
string key (and probably a few other situations with string keys).
This was reported with a patch as pybsddb sourceforge bug 1708868 by
jjjhhhlll at gmail.
........
r58386 | gregory.p.smith | 2007-10-09 00:19:11 -0700 (Tue, 09 Oct 2007) | 3 lines
Use the highest cPickle protocol in bsddb.dbshelve. This comes from
sourceforge pybsddb patch 1551443 by w_barnes.
........
r58394 | gregory.p.smith | 2007-10-09 11:26:02 -0700 (Tue, 09 Oct 2007) | 2 lines
remove another sleepycat reference
........
r58396 | kurt.kaiser | 2007-10-09 12:31:30 -0700 (Tue, 09 Oct 2007) | 3 lines
Allow interrupt only when executing user code in subprocess
Patch 1225 Tal Einat modified from IDLE-Spoon.
........
r58399 | brett.cannon | 2007-10-09 17:07:50 -0700 (Tue, 09 Oct 2007) | 5 lines
Remove file-level typedefs that were inconsistently used throughout the file.
Just move over to the public API names.
Closes issue1238.
........
r58401 | raymond.hettinger | 2007-10-09 17:26:46 -0700 (Tue, 09 Oct 2007) | 1 line
Accept Jim Jewett's api suggestion to use None instead of -1 to indicate unbounded deques.
........
r58403 | kurt.kaiser | 2007-10-09 17:55:40 -0700 (Tue, 09 Oct 2007) | 2 lines
Allow cursor color change w/o restart. Patch 1725576 Tal Einat.
........
r58404 | kurt.kaiser | 2007-10-09 18:06:47 -0700 (Tue, 09 Oct 2007) | 2 lines
show paste if > 80 columns. Patch 1659326 Tal Einat.
........
r58415 | thomas.heller | 2007-10-11 12:51:32 -0700 (Thu, 11 Oct 2007) | 5 lines
On OS X, use os.uname() instead of gestalt.sysv(...) to get the
operating system version. This allows to use ctypes when Python
was configured with --disable-toolbox-glue.
........
r58419 | neal.norwitz | 2007-10-11 20:01:01 -0700 (Thu, 11 Oct 2007) | 1 line
Get rid of warning about not being able to create an existing directory.
........
r58420 | neal.norwitz | 2007-10-11 20:01:30 -0700 (Thu, 11 Oct 2007) | 1 line
Get rid of warnings on a bunch of platforms by using a proper prototype.
........
r58421 | neal.norwitz | 2007-10-11 20:01:54 -0700 (Thu, 11 Oct 2007) | 4 lines
Get rid of compiler warning about retval being used (returned) without
being initialized. (gcc warning and Coverity 202)
........
r58422 | neal.norwitz | 2007-10-11 20:03:23 -0700 (Thu, 11 Oct 2007) | 1 line
Fix Coverity 168: Close the file before returning (exiting).
........
r58423 | neal.norwitz | 2007-10-11 20:04:18 -0700 (Thu, 11 Oct 2007) | 4 lines
Fix Coverity 180: Don't overallocate. We don't need structs, but pointers.
Also fix a memory leak.
........
r58424 | neal.norwitz | 2007-10-11 20:05:19 -0700 (Thu, 11 Oct 2007) | 5 lines
Fix Coverity 185-186: If the passed in FILE is NULL, uninitialized memory
would be accessed.
Will backport.
........
r58425 | neal.norwitz | 2007-10-11 20:52:34 -0700 (Thu, 11 Oct 2007) | 1 line
Get this module to compile with bsddb versions prior to 4.3
........
r58430 | martin.v.loewis | 2007-10-12 01:56:52 -0700 (Fri, 12 Oct 2007) | 3 lines
Bug #1216: Restore support for Visual Studio 2002.
Will backport to 2.5.
........
r58433 | raymond.hettinger | 2007-10-12 10:53:11 -0700 (Fri, 12 Oct 2007) | 1 line
Fix test of count.__repr__() to ignore the 'L' if the count is a long
........
r58434 | gregory.p.smith | 2007-10-12 11:44:06 -0700 (Fri, 12 Oct 2007) | 4 lines
Fixes http://bugs.python.org/issue1233 - bsddb.dbshelve.DBShelf.append
was useless due to inverted logic. Also adds a test case for RECNO dbs
to test_dbshelve.
........
r58445 | georg.brandl | 2007-10-13 06:20:03 -0700 (Sat, 13 Oct 2007) | 2 lines
Fix email example.
........
r58450 | gregory.p.smith | 2007-10-13 16:02:05 -0700 (Sat, 13 Oct 2007) | 2 lines
Fix an uncollectable reference leak in bsddb.db.DBShelf.append
........
r58453 | neal.norwitz | 2007-10-13 17:18:40 -0700 (Sat, 13 Oct 2007) | 8 lines
Let the O/S supply a port if none of the default ports can be used.
This should make the tests more robust at the expense of allowing
tests to be sloppier by not requiring them to cleanup after themselves.
(It will legitamitely help when running two test suites simultaneously
or if another process is already using one of the predefined ports.)
Also simplifies (slightLy) the exception handling elsewhere.
........
r58459 | neal.norwitz | 2007-10-14 11:30:21 -0700 (Sun, 14 Oct 2007) | 2 lines
Don't raise a string exception, they don't work anymore.
........
r58460 | neal.norwitz | 2007-10-14 11:40:37 -0700 (Sun, 14 Oct 2007) | 1 line
Use unittest for assertions
........
r58468 | armin.rigo | 2007-10-15 00:48:35 -0700 (Mon, 15 Oct 2007) | 2 lines
test_bigbits was not testing what it seemed to.
........
r58471 | guido.van.rossum | 2007-10-15 08:54:11 -0700 (Mon, 15 Oct 2007) | 3 lines
Change a PyErr_Print() into a PyErr_Clear(),
per discussion in issue 1031213.
........
r58500 | raymond.hettinger | 2007-10-16 12:18:30 -0700 (Tue, 16 Oct 2007) | 1 line
Improve error messages
........
r58506 | raymond.hettinger | 2007-10-16 14:28:32 -0700 (Tue, 16 Oct 2007) | 1 line
More docs, error messages, and tests
........
r58507 | andrew.kuchling | 2007-10-16 15:58:03 -0700 (Tue, 16 Oct 2007) | 1 line
Add items
........
r58508 | brett.cannon | 2007-10-16 16:24:06 -0700 (Tue, 16 Oct 2007) | 3 lines
Remove ``:const:`` notation on None in parameter list. Since the markup is not
rendered for parameters it just showed up as ``:const:`None` `` in the output.
........
r58509 | brett.cannon | 2007-10-16 16:26:45 -0700 (Tue, 16 Oct 2007) | 3 lines
Re-order some functions whose parameters differ between PyObject and const char
* so that they are next to each other.
........
r58522 | armin.rigo | 2007-10-17 11:46:37 -0700 (Wed, 17 Oct 2007) | 5 lines
Fix the overflow checking of list_repeat.
Introduce overflow checking into list_inplace_repeat.
Backport candidate, possibly.
........
r58530 | facundo.batista | 2007-10-17 20:16:03 -0700 (Wed, 17 Oct 2007) | 7 lines
Issue #1580738. When HTTPConnection reads the whole stream with read(),
it closes itself. When the stream is read in several calls to read(n),
it should behave in the same way if HTTPConnection knows where the end
of the stream is (through self.length). Added a test case for this
behaviour.
........
r58531 | facundo.batista | 2007-10-17 20:44:48 -0700 (Wed, 17 Oct 2007) | 3 lines
Issue 1289, just a typo.
........
r58532 | gregory.p.smith | 2007-10-18 00:56:54 -0700 (Thu, 18 Oct 2007) | 4 lines
cleanup test_dbtables to use mkdtemp. cleanup dbtables to pass txn as a
keyword argument whenever possible to avoid bugs and confusion. (dbtables.py
line 447 self.db.get using txn as a non-keyword was an actual bug due to this)
........
r58533 | gregory.p.smith | 2007-10-18 01:34:20 -0700 (Thu, 18 Oct 2007) | 4 lines
Fix a weird bug in dbtables: if it chose a random rowid string that contained
NULL bytes it would cause the database all sorts of problems in the future
leading to very strange random failures and corrupt dbtables.bsdTableDb dbs.
........
r58534 | gregory.p.smith | 2007-10-18 09:32:02 -0700 (Thu, 18 Oct 2007) | 3 lines
A cleaner fix than the one committed last night. Generate random rowids that
do not contain null bytes.
........
r58537 | gregory.p.smith | 2007-10-18 10:17:57 -0700 (Thu, 18 Oct 2007) | 2 lines
mention bsddb fixes.
........
r58538 | raymond.hettinger | 2007-10-18 14:13:06 -0700 (Thu, 18 Oct 2007) | 1 line
Remove useless warning
........
r58539 | gregory.p.smith | 2007-10-19 00:31:20 -0700 (Fri, 19 Oct 2007) | 2 lines
squelch the warning that this test is supposed to trigger.
........
r58542 | georg.brandl | 2007-10-19 05:32:39 -0700 (Fri, 19 Oct 2007) | 2 lines
Clarify wording for apply().
........
r58544 | mark.summerfield | 2007-10-19 05:48:17 -0700 (Fri, 19 Oct 2007) | 3 lines
Added a cross-ref to each other.
........
r58545 | georg.brandl | 2007-10-19 10:38:49 -0700 (Fri, 19 Oct 2007) | 2 lines
#1284: "S" means "seen", not unread.
........
r58548 | thomas.heller | 2007-10-19 11:11:41 -0700 (Fri, 19 Oct 2007) | 4 lines
Fix ctypes on 32-bit systems when Python is configured --with-system-ffi.
See also https://bugs.launchpad.net/bugs/72505.
Ported from release25-maint branch.
........
r58550 | facundo.batista | 2007-10-19 12:25:57 -0700 (Fri, 19 Oct 2007) | 8 lines
The constructor from tuple was way too permissive: it allowed bad
coefficient numbers, floats in the sign, and other details that
generated directly the wrong number in the best case, or triggered
misfunctionality in the alorithms.
Test cases added for these issues. Thanks Mark Dickinson.
........
r58559 | georg.brandl | 2007-10-20 06:22:53 -0700 (Sat, 20 Oct 2007) | 2 lines
Fix code being interpreted as a target.
........
r58561 | georg.brandl | 2007-10-20 06:36:24 -0700 (Sat, 20 Oct 2007) | 2 lines
Document new "cmdoption" directive.
........
r58562 | georg.brandl | 2007-10-20 08:21:22 -0700 (Sat, 20 Oct 2007) | 2 lines
Make a path more Unix-standardy.
........
r58564 | georg.brandl | 2007-10-20 10:51:39 -0700 (Sat, 20 Oct 2007) | 2 lines
Document new directive "envvar".
........
r58567 | georg.brandl | 2007-10-20 11:08:14 -0700 (Sat, 20 Oct 2007) | 6 lines
* Add new toplevel chapter, "Using Python." (how to install,
configure and setup python on different platforms -- at least
in theory.)
* Move the Python on Mac docs in that chapter.
* Add a new chapter about the command line invocation, by stargaming.
........
r58568 | georg.brandl | 2007-10-20 11:33:20 -0700 (Sat, 20 Oct 2007) | 2 lines
Change title, for now.
........
r58569 | georg.brandl | 2007-10-20 11:39:25 -0700 (Sat, 20 Oct 2007) | 2 lines
Add entry to ACKS.
........
r58570 | georg.brandl | 2007-10-20 12:05:45 -0700 (Sat, 20 Oct 2007) | 2 lines
Clarify -E docs.
........
r58571 | georg.brandl | 2007-10-20 12:08:36 -0700 (Sat, 20 Oct 2007) | 2 lines
Even more clarification.
........
r58572 | andrew.kuchling | 2007-10-20 12:25:37 -0700 (Sat, 20 Oct 2007) | 1 line
Fix protocol name
........
r58573 | andrew.kuchling | 2007-10-20 12:35:18 -0700 (Sat, 20 Oct 2007) | 1 line
Various items
........
r58574 | andrew.kuchling | 2007-10-20 12:39:35 -0700 (Sat, 20 Oct 2007) | 1 line
Use correct header line
........
r58576 | armin.rigo | 2007-10-21 02:14:15 -0700 (Sun, 21 Oct 2007) | 3 lines
Add a crasher for the long-standing issue with closing a file
while another thread uses it.
........
r58577 | georg.brandl | 2007-10-21 03:01:56 -0700 (Sun, 21 Oct 2007) | 2 lines
Remove duplicate crasher.
........
r58578 | georg.brandl | 2007-10-21 03:24:20 -0700 (Sun, 21 Oct 2007) | 2 lines
Unify "byte code" to "bytecode". Also sprinkle :term: markup for it.
........
r58579 | georg.brandl | 2007-10-21 03:32:54 -0700 (Sun, 21 Oct 2007) | 2 lines
Add markup to new function descriptions.
........
r58580 | georg.brandl | 2007-10-21 03:45:46 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for descriptors.
........
r58581 | georg.brandl | 2007-10-21 03:46:24 -0700 (Sun, 21 Oct 2007) | 2 lines
Unify "file-descriptor" to "file descriptor".
........
r58582 | georg.brandl | 2007-10-21 03:52:38 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term: for generators.
........
r58583 | georg.brandl | 2007-10-21 05:10:28 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for iterator.
........
r58584 | georg.brandl | 2007-10-21 05:15:05 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for "new-style class".
........
r58588 | neal.norwitz | 2007-10-21 21:47:54 -0700 (Sun, 21 Oct 2007) | 1 line
Add Chris Monson so he can edit PEPs.
........
r58594 | guido.van.rossum | 2007-10-22 09:27:19 -0700 (Mon, 22 Oct 2007) | 4 lines
Issue #1307, patch by Derek Shockey.
When "MAIL" is received without args, an exception happens instead of
sending a 501 syntax error response.
........
r58598 | travis.oliphant | 2007-10-22 19:40:56 -0700 (Mon, 22 Oct 2007) | 1 line
Add phuang patch from Issue 708374 which adds offset parameter to mmap module.
........
r58601 | neal.norwitz | 2007-10-22 22:44:27 -0700 (Mon, 22 Oct 2007) | 2 lines
Bug #1313, fix typo (wrong variable name) in example.
........
r58609 | georg.brandl | 2007-10-23 11:21:35 -0700 (Tue, 23 Oct 2007) | 2 lines
Update Pygments version from externals.
........
r58618 | guido.van.rossum | 2007-10-23 12:25:41 -0700 (Tue, 23 Oct 2007) | 3 lines
Issue 1307 by Derek Shockey, fox the same bug for RCPT.
Neal: please backport!
........
r58620 | raymond.hettinger | 2007-10-23 13:37:41 -0700 (Tue, 23 Oct 2007) | 1 line
Shorter name for namedtuple()
........
r58621 | andrew.kuchling | 2007-10-23 13:55:47 -0700 (Tue, 23 Oct 2007) | 1 line
Update name
........
r58622 | raymond.hettinger | 2007-10-23 14:23:07 -0700 (Tue, 23 Oct 2007) | 1 line
Fixup news entry
........
r58623 | raymond.hettinger | 2007-10-23 18:28:33 -0700 (Tue, 23 Oct 2007) | 1 line
Optimize sum() for integer and float inputs.
........
r58624 | raymond.hettinger | 2007-10-23 19:05:51 -0700 (Tue, 23 Oct 2007) | 1 line
Fixup error return and add support for intermixed ints and floats/
........
r58628 | vinay.sajip | 2007-10-24 03:47:06 -0700 (Wed, 24 Oct 2007) | 1 line
Bug #1321: Fixed logic error in TimedRotatingFileHandler.__init__()
........
r58641 | facundo.batista | 2007-10-24 12:11:08 -0700 (Wed, 24 Oct 2007) | 4 lines
Issue 1290. CharacterData.__repr__ was constructing a string
in response that keeped having a non-ascii character.
........
r58643 | thomas.heller | 2007-10-24 12:50:45 -0700 (Wed, 24 Oct 2007) | 1 line
Added unittest for calling a function with paramflags (backport from py3k branch).
........
r58645 | matthias.klose | 2007-10-24 13:00:44 -0700 (Wed, 24 Oct 2007) | 2 lines
- Build using system ffi library on arm*-linux*.
........
r58651 | georg.brandl | 2007-10-24 14:40:38 -0700 (Wed, 24 Oct 2007) | 2 lines
Bug #1287: make os.environ.pop() work as expected.
........
r58652 | raymond.hettinger | 2007-10-24 19:26:58 -0700 (Wed, 24 Oct 2007) | 1 line
Missing DECREFs
........
r58653 | matthias.klose | 2007-10-24 23:37:24 -0700 (Wed, 24 Oct 2007) | 2 lines
- Build using system ffi library on arm*-linux*, pass --with-system-ffi to CONFIG_ARGS
........
r58655 | thomas.heller | 2007-10-25 12:47:32 -0700 (Thu, 25 Oct 2007) | 2 lines
ffi_type_longdouble may be already #defined.
See issue 1324.
........
r58656 | kurt.kaiser | 2007-10-25 15:43:45 -0700 (Thu, 25 Oct 2007) | 3 lines
Correct an ancient bug in an unused path by removing that path: register() is
now idempotent.
........
r58660 | kurt.kaiser | 2007-10-25 17:10:09 -0700 (Thu, 25 Oct 2007) | 4 lines
1. Add comments to provide top-level documentation.
2. Refactor to use more descriptive names.
3. Enhance tests in main().
........
r58675 | georg.brandl | 2007-10-26 11:30:41 -0700 (Fri, 26 Oct 2007) | 2 lines
Fix new pop() method on os.environ on ignorecase-platforms.
........
r58696 | neal.norwitz | 2007-10-27 15:32:21 -0700 (Sat, 27 Oct 2007) | 1 line
Update URL for Pygments. 0.8.1 is no longer available
........
r58697 | hyeshik.chang | 2007-10-28 04:19:02 -0700 (Sun, 28 Oct 2007) | 3 lines
- Add support for FreeBSD 8 which is recently forked from FreeBSD 7.
- Regenerate IN module for most recent maintenance tree of FreeBSD 6 and 7.
........
r58698 | hyeshik.chang | 2007-10-28 05:38:09 -0700 (Sun, 28 Oct 2007) | 2 lines
Enable platform-specific tweaks for FreeBSD 8 (exactly same to FreeBSD 7's yet)
........
r58700 | kurt.kaiser | 2007-10-28 12:03:59 -0700 (Sun, 28 Oct 2007) | 2 lines
Add confirmation dialog before printing. Patch 1717170 Tal Einat.
........
r58706 | guido.van.rossum | 2007-10-29 13:52:45 -0700 (Mon, 29 Oct 2007) | 3 lines
Patch 1353 by Jacob Winther.
Add mp4 mapping to mimetypes.py.
........
r58709 | guido.van.rossum | 2007-10-29 15:15:05 -0700 (Mon, 29 Oct 2007) | 6 lines
Backport fixes for the code that decodes octal escapes (and for PyString
also hex escapes) -- this was reaching beyond the end of the input string
buffer, even though it is not supposed to be \0-terminated.
This has no visible effect but is clearly the correct thing to do.
(In 3.0 it had a visible effect after removing ob_sstate from PyString.)
........
r58710 | kurt.kaiser | 2007-10-29 19:38:54 -0700 (Mon, 29 Oct 2007) | 7 lines
check in Tal Einat's update to tabpage.py
Patch 1612746
M configDialog.py
M NEWS.txt
AM tabbedpages.py
........
r58715 | georg.brandl | 2007-10-30 10:51:18 -0700 (Tue, 30 Oct 2007) | 2 lines
Use correct markup.
........
r58716 | georg.brandl | 2007-10-30 10:57:12 -0700 (Tue, 30 Oct 2007) | 2 lines
Make example about hiding None return values at the prompt clearer.
........
r58728 | neal.norwitz | 2007-10-30 23:33:20 -0700 (Tue, 30 Oct 2007) | 1 line
Fix some compiler warnings for signed comparisons on Unix and Windows.
........
r58731 | martin.v.loewis | 2007-10-31 10:19:33 -0700 (Wed, 31 Oct 2007) | 2 lines
Adding Christian Heimes.
........
r58737 | raymond.hettinger | 2007-10-31 14:57:58 -0700 (Wed, 31 Oct 2007) | 1 line
Clarify the reasons why pickle is almost always better than marshal
........
r58739 | raymond.hettinger | 2007-10-31 15:15:49 -0700 (Wed, 31 Oct 2007) | 1 line
Sets are marshalable.
........
2007-11-01 17:32:30 -03:00
|
|
|
applied: runs of consecutive whitespace are regarded as a single separator,
|
|
|
|
and the result will contain no empty strings at the start or end if the
|
|
|
|
string has leading or trailing whitespace. Consequently, splitting an empty
|
|
|
|
string or a string consisting of just whitespace with a ``None`` separator
|
|
|
|
returns ``[]``.
|
|
|
|
|
2014-08-09 03:14:04 -03:00
|
|
|
For example::
|
|
|
|
|
|
|
|
>>> '1 2 3'.split()
|
|
|
|
['1', '2', '3']
|
|
|
|
>>> '1 2 3'.split(maxsplit=1)
|
|
|
|
['1', '2 3']
|
|
|
|
>>> ' 1 2 3 '.split()
|
|
|
|
['1', '2', '3']
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2012-08-15 11:43:58 -03:00
|
|
|
.. index::
|
|
|
|
single: universal newlines; str.splitlines method
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. method:: str.splitlines([keepends])
|
|
|
|
|
2015-03-31 22:20:36 -03:00
|
|
|
Return a list of the lines in the string, breaking at line boundaries. Line
|
|
|
|
breaks are not included in the resulting list unless *keepends* is given and
|
|
|
|
true.
|
|
|
|
|
|
|
|
This method splits on the following line boundaries. In particular, the
|
|
|
|
boundaries are a superset of :term:`universal newlines`.
|
|
|
|
|
|
|
|
+-----------------------+-----------------------------+
|
|
|
|
| Representation | Description |
|
|
|
|
+=======================+=============================+
|
|
|
|
| ``\n`` | Line Feed |
|
|
|
|
+-----------------------+-----------------------------+
|
|
|
|
| ``\r`` | Carriage Return |
|
|
|
|
+-----------------------+-----------------------------+
|
|
|
|
| ``\r\n`` | Carriage Return + Line Feed |
|
|
|
|
+-----------------------+-----------------------------+
|
|
|
|
| ``\v`` or ``\x0b`` | Line Tabulation |
|
|
|
|
+-----------------------+-----------------------------+
|
|
|
|
| ``\f`` or ``\x0c`` | Form Feed |
|
|
|
|
+-----------------------+-----------------------------+
|
|
|
|
| ``\x1c`` | File Separator |
|
|
|
|
+-----------------------+-----------------------------+
|
|
|
|
| ``\x1d`` | Group Separator |
|
|
|
|
+-----------------------+-----------------------------+
|
|
|
|
| ``\x1e`` | Record Separator |
|
|
|
|
+-----------------------+-----------------------------+
|
|
|
|
| ``\x85`` | Next Line (C1 Control Code) |
|
|
|
|
+-----------------------+-----------------------------+
|
|
|
|
| ``\u2028`` | Line Separator |
|
|
|
|
+-----------------------+-----------------------------+
|
|
|
|
| ``\u2029`` | Paragraph Separator |
|
|
|
|
+-----------------------+-----------------------------+
|
|
|
|
|
|
|
|
.. versionchanged:: 3.2
|
|
|
|
|
|
|
|
``\v`` and ``\f`` added to list of line boundaries.
|
2012-06-01 17:19:36 -03:00
|
|
|
|
2014-08-09 03:14:04 -03:00
|
|
|
For example::
|
|
|
|
|
|
|
|
>>> 'ab c\n\nde fg\rkl\r\n'.splitlines()
|
2014-10-05 23:03:48 -03:00
|
|
|
['ab c', '', 'de fg', 'kl']
|
2014-08-09 03:14:04 -03:00
|
|
|
>>> 'ab c\n\nde fg\rkl\r\n'.splitlines(keepends=True)
|
|
|
|
['ab c\n', '\n', 'de fg\r', 'kl\r\n']
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-06 17:08:09 -03:00
|
|
|
Unlike :meth:`~str.split` when a delimiter string *sep* is given, this
|
|
|
|
method returns an empty list for the empty string, and a terminal line
|
2014-08-09 03:14:04 -03:00
|
|
|
break does not result in an extra line::
|
|
|
|
|
|
|
|
>>> "".splitlines()
|
|
|
|
[]
|
|
|
|
>>> "One line\n".splitlines()
|
|
|
|
['One line']
|
|
|
|
|
|
|
|
For comparison, ``split('\n')`` gives::
|
|
|
|
|
|
|
|
>>> ''.split('\n')
|
|
|
|
['']
|
|
|
|
>>> 'Two lines\n'.split('\n')
|
|
|
|
['Two lines', '']
|
2012-08-06 17:08:09 -03:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. method:: str.startswith(prefix[, start[, end]])
|
|
|
|
|
|
|
|
Return ``True`` if string starts with the *prefix*, otherwise return ``False``.
|
|
|
|
*prefix* can also be a tuple of prefixes to look for. With optional *start*,
|
|
|
|
test string beginning at that position. With optional *end*, stop comparing
|
|
|
|
string at that position.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: str.strip([chars])
|
|
|
|
|
|
|
|
Return a copy of the string with the leading and trailing characters removed.
|
|
|
|
The *chars* argument is a string specifying the set of characters to be removed.
|
|
|
|
If omitted or ``None``, the *chars* argument defaults to removing whitespace.
|
|
|
|
The *chars* argument is not a prefix or suffix; rather, all combinations of its
|
2014-08-09 03:14:04 -03:00
|
|
|
values are stripped::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
>>> ' spacious '.strip()
|
|
|
|
'spacious'
|
|
|
|
>>> 'www.example.com'.strip('cmowz.')
|
|
|
|
'example'
|
|
|
|
|
2015-05-23 13:11:55 -03:00
|
|
|
The outermost leading and trailing *chars* argument values are stripped
|
|
|
|
from the string. Characters are removed from the leading end until
|
|
|
|
reaching a string character that is not contained in the set of
|
|
|
|
characters in *chars*. A similar action takes place on the trailing end.
|
|
|
|
For example::
|
|
|
|
|
|
|
|
>>> comment_string = '#....... Section 3.2.1 Issue #32 .......'
|
|
|
|
>>> comment_string.strip('.#! ')
|
|
|
|
'Section 3.2.1 Issue #32'
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. method:: str.swapcase()
|
|
|
|
|
|
|
|
Return a copy of the string with uppercase characters converted to lowercase and
|
2012-01-11 19:17:06 -04:00
|
|
|
vice versa. Note that it is not necessarily true that
|
|
|
|
``s.swapcase().swapcase() == s``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. method:: str.title()
|
|
|
|
|
2009-09-29 03:22:28 -03:00
|
|
|
Return a titlecased version of the string where words start with an uppercase
|
|
|
|
character and the remaining characters are lowercase.
|
|
|
|
|
2014-08-09 03:14:04 -03:00
|
|
|
For example::
|
|
|
|
|
|
|
|
>>> 'Hello world'.title()
|
|
|
|
'Hello World'
|
|
|
|
|
2009-09-29 03:22:28 -03:00
|
|
|
The algorithm uses a simple language-independent definition of a word as
|
|
|
|
groups of consecutive letters. The definition works in many contexts but
|
|
|
|
it means that apostrophes in contractions and possessives form word
|
|
|
|
boundaries, which may not be the desired result::
|
|
|
|
|
|
|
|
>>> "they're bill's friends from the UK".title()
|
|
|
|
"They'Re Bill'S Friends From The Uk"
|
|
|
|
|
|
|
|
A workaround for apostrophes can be constructed using regular expressions::
|
|
|
|
|
|
|
|
>>> import re
|
|
|
|
>>> def titlecase(s):
|
2012-11-08 11:26:53 -04:00
|
|
|
... return re.sub(r"[A-Za-z]+('[A-Za-z]+)?",
|
|
|
|
... lambda mo: mo.group(0)[0].upper() +
|
|
|
|
... mo.group(0)[1:].lower(),
|
|
|
|
... s)
|
|
|
|
...
|
2009-09-29 03:22:28 -03:00
|
|
|
>>> titlecase("they're bill's friends.")
|
|
|
|
"They're Bill's Friends."
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2015-08-06 01:54:15 -03:00
|
|
|
.. method:: str.translate(table)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2015-08-06 01:54:15 -03:00
|
|
|
Return a copy of the string in which each character has been mapped through
|
|
|
|
the given translation table. The table must be an object that implements
|
|
|
|
indexing via :meth:`__getitem__`, typically a :term:`mapping` or
|
|
|
|
:term:`sequence`. When indexed by a Unicode ordinal (an integer), the
|
|
|
|
table object can do any of the following: return a Unicode ordinal or a
|
|
|
|
string, to map the character to one or more other characters; return
|
|
|
|
``None``, to delete the character from the return string; or raise a
|
|
|
|
:exc:`LookupError` exception, to map the character to itself.
|
2007-11-27 19:48:05 -04:00
|
|
|
|
2008-12-27 19:33:20 -04:00
|
|
|
You can use :meth:`str.maketrans` to create a translation map from
|
|
|
|
character-to-character mappings in different formats.
|
Merged revisions 61724-61725,61731-61735,61737,61739,61741,61743-61744,61753,61761,61765-61767,61769,61773,61776-61778,61780-61783,61788,61793,61796,61807,61813 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sat, 22 Mar 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 M?\195?\164r 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 M?\195?\164r 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 M?\195?\164r 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 M?\195?\164r 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 M?\195?\164r 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 M?\195?\164r 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 M?\195?\164r 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 M?\195?\164r 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 M?\195?\164r 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 M?\195?\164r 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 M?\195?\164r 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sat, 22 Mar 2008) | 2 lines
Install lib2to3.
................
r61731 | facundo.batista | 2008-03-22 03:45:37 +0100 (Sat, 22 Mar 2008) | 4 lines
Small fix that complicated the test actually when that
test failed.
................
r61732 | alexandre.vassalotti | 2008-03-22 05:08:44 +0100 (Sat, 22 Mar 2008) | 2 lines
Added warning for the removal of 'hotshot' in Py3k.
................
r61733 | georg.brandl | 2008-03-22 11:07:29 +0100 (Sat, 22 Mar 2008) | 4 lines
#1918: document that weak references *to* an object are
cleared before the object's __del__ is called, to ensure that the weak
reference callback (if any) finds the object healthy.
................
r61734 | georg.brandl | 2008-03-22 11:56:23 +0100 (Sat, 22 Mar 2008) | 2 lines
Activate the Sphinx doctest extension and convert howto/functional to use it.
................
r61735 | georg.brandl | 2008-03-22 11:58:38 +0100 (Sat, 22 Mar 2008) | 2 lines
Allow giving source names on the cmdline.
................
r61737 | georg.brandl | 2008-03-22 12:00:48 +0100 (Sat, 22 Mar 2008) | 2 lines
Fixup this HOWTO's doctest blocks so that they can be run with sphinx' doctest builder.
................
r61739 | georg.brandl | 2008-03-22 12:47:10 +0100 (Sat, 22 Mar 2008) | 2 lines
Test decimal.rst doctests as far as possible with sphinx doctest.
................
r61741 | georg.brandl | 2008-03-22 13:04:26 +0100 (Sat, 22 Mar 2008) | 2 lines
Make doctests in re docs usable with sphinx' doctest.
................
r61743 | georg.brandl | 2008-03-22 13:59:37 +0100 (Sat, 22 Mar 2008) | 2 lines
Make more doctests in pprint docs testable.
................
r61744 | georg.brandl | 2008-03-22 14:07:06 +0100 (Sat, 22 Mar 2008) | 2 lines
No need to specify explicit "doctest_block" anymore.
................
r61753 | georg.brandl | 2008-03-22 21:08:43 +0100 (Sat, 22 Mar 2008) | 2 lines
Fix-up syntax problems.
................
r61761 | georg.brandl | 2008-03-22 22:06:20 +0100 (Sat, 22 Mar 2008) | 4 lines
Make collections' doctests executable.
(The <BLANKLINE>s will be stripped from presentation output.)
................
r61765 | georg.brandl | 2008-03-22 22:21:57 +0100 (Sat, 22 Mar 2008) | 2 lines
Test doctests in datetime docs.
................
r61766 | georg.brandl | 2008-03-22 22:26:44 +0100 (Sat, 22 Mar 2008) | 2 lines
Test doctests in operator docs.
................
r61767 | georg.brandl | 2008-03-22 22:38:33 +0100 (Sat, 22 Mar 2008) | 2 lines
Enable doctests in functions.rst. Already found two errors :)
................
r61769 | georg.brandl | 2008-03-22 23:04:10 +0100 (Sat, 22 Mar 2008) | 3 lines
Enable doctest running for several other documents.
We have now over 640 doctests that are run with "make doctest".
................
r61773 | raymond.hettinger | 2008-03-23 01:55:46 +0100 (Sun, 23 Mar 2008) | 1 line
Simplify demo code.
................
r61776 | neal.norwitz | 2008-03-23 04:43:33 +0100 (Sun, 23 Mar 2008) | 7 lines
Try to make this test a little more robust and not fail with:
timeout (10.0025) is more than 2 seconds more than expected (0.001)
I'm assuming this problem is caused by DNS lookup. This change
does a DNS lookup of the hostname before trying to connect, so the time
is not included.
................
r61777 | neal.norwitz | 2008-03-23 05:08:30 +0100 (Sun, 23 Mar 2008) | 1 line
Speed up the test by avoiding socket timeouts.
................
r61778 | neal.norwitz | 2008-03-23 05:43:09 +0100 (Sun, 23 Mar 2008) | 1 line
Skip the epoll test if epoll() does not work
................
r61780 | neal.norwitz | 2008-03-23 06:47:20 +0100 (Sun, 23 Mar 2008) | 1 line
Suppress failure (to avoid a flaky test) if we cannot connect to svn.python.org
................
r61781 | neal.norwitz | 2008-03-23 07:13:25 +0100 (Sun, 23 Mar 2008) | 4 lines
Move itertools before future_builtins since the latter depends on the former.
From a clean build importing future_builtins would fail since itertools
wasn't built yet.
................
r61782 | neal.norwitz | 2008-03-23 07:16:04 +0100 (Sun, 23 Mar 2008) | 1 line
Try to prevent the alarm going off early in tearDown
................
r61783 | neal.norwitz | 2008-03-23 07:19:57 +0100 (Sun, 23 Mar 2008) | 4 lines
Remove compiler warnings (on Alpha at least) about using chars as
array subscripts. Using chars are dangerous b/c they are signed
on some platforms and unsigned on others.
................
r61788 | georg.brandl | 2008-03-23 09:05:30 +0100 (Sun, 23 Mar 2008) | 2 lines
Make the doctests presentation-friendlier.
................
r61793 | amaury.forgeotdarc | 2008-03-23 10:55:29 +0100 (Sun, 23 Mar 2008) | 4 lines
#1477: ur'\U0010FFFF' raised in narrow unicode builds.
Corrected the raw-unicode-escape codec to use UTF-16 surrogates in
this case, just like the unicode-escape codec.
................
r61796 | raymond.hettinger | 2008-03-23 14:32:32 +0100 (Sun, 23 Mar 2008) | 1 line
Issue 1681432: Add triangular distribution the random module.
................
r61807 | raymond.hettinger | 2008-03-23 20:37:53 +0100 (Sun, 23 Mar 2008) | 4 lines
Adopt Nick's suggestion for useful default arguments.
Clean-up floating point issues by adding true division and float constants.
................
r61813 | gregory.p.smith | 2008-03-23 22:04:43 +0100 (Sun, 23 Mar 2008) | 6 lines
Fix gzip to deal with CRC's being signed values in Python 2.x properly and to
read 32bit values as unsigned to start with rather than applying signedness
fixups allover the place afterwards.
This hopefully fixes the test_tarfile failure on the alpha/tru64 buildbot.
................
2008-03-23 18:54:12 -03:00
|
|
|
|
2015-08-06 01:54:15 -03:00
|
|
|
See also the :mod:`codecs` module for a more flexible approach to custom
|
|
|
|
character mappings.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. method:: str.upper()
|
|
|
|
|
2011-08-15 08:27:19 -03:00
|
|
|
Return a copy of the string with all the cased characters [4]_ converted to
|
|
|
|
uppercase. Note that ``str.upper().isupper()`` might be ``False`` if ``s``
|
|
|
|
contains uncased characters or if the Unicode category of the resulting
|
2012-01-19 00:09:32 -04:00
|
|
|
character(s) is not "Lu" (Letter, uppercase), but e.g. "Lt" (Letter,
|
|
|
|
titlecase).
|
|
|
|
|
|
|
|
The uppercasing algorithm used is described in section 3.13 of the Unicode
|
|
|
|
Standard.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. method:: str.zfill(width)
|
|
|
|
|
2014-08-09 03:14:04 -03:00
|
|
|
Return a copy of the string left filled with ASCII ``'0'`` digits to
|
2015-04-06 07:04:49 -03:00
|
|
|
make a string of length *width*. A leading sign prefix (``'+'``/``'-'``)
|
2014-08-09 03:14:04 -03:00
|
|
|
is handled by inserting the padding *after* the sign character rather
|
|
|
|
than before. The original string is returned if *width* is less than
|
|
|
|
or equal to ``len(s)``.
|
|
|
|
|
|
|
|
For example::
|
|
|
|
|
|
|
|
>>> "42".zfill(5)
|
|
|
|
'00042'
|
|
|
|
>>> "-42".zfill(5)
|
|
|
|
'-0042'
|
Merged revisions 61431,61433-61436,61439,61444,61449-61450,61453,61458,61465,61468,61471-61474,61480,61483-61484,61488,61495-61496,61498,61503-61504,61507,61509-61510,61515-61518 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r61431 | vinay.sajip | 2008-03-16 22:35:58 +0100 (So, 16 Mär 2008) | 1 line
Clarified documentation on use of shutdown().
........
r61433 | mark.summerfield | 2008-03-17 09:28:15 +0100 (Mo, 17 Mär 2008) | 5 lines
Added a footnote to each pointing out that for XML output if an encoding
string is given it should conform to the appropriate XML standards---for
example, "UTF-8" is okay, but "UTF8" is not.
........
r61434 | eric.smith | 2008-03-17 12:01:01 +0100 (Mo, 17 Mär 2008) | 7 lines
Issue 2264: empty float presentation type needs to have at least one digit past the decimal point.
Added "Z" format_char to PyOS_ascii_formatd to support empty float presentation type.
Renamed buf_size in PyOS_ascii_formatd to more accurately reflect it's meaning.
Modified format.__float__ to use the new "Z" format as the default.
Added test cases.
........
r61435 | eric.smith | 2008-03-17 13:14:29 +0100 (Mo, 17 Mär 2008) | 2 lines
Reformated lines > 79 chars.
Deleted unused macro ISXDIGIT.
........
r61436 | jeffrey.yasskin | 2008-03-17 15:40:53 +0100 (Mo, 17 Mär 2008) | 13 lines
Allow Gnu gcc's to build python on OSX by removing -Wno-long-double,
-no-cpp-precomp, and -mno-fused-madd from configure.
* r22183 added -no-cpp-precomp, which
http://gcc.gnu.org/ml/gcc/2005-12/msg00368.html claims hasn't been
needed since gcc-3.1.
* r25607 added -Wno-long-double to avoid a warning in
Include/objimpl.h (issue 525481). The long double is still there,
but OSX 10.4's gcc no longer warns about it.
* r33666 fixed issue 775892 on OSX 10.3 by adding -mno-fused-madd,
which changed the sign of some float 0s. Tim Peters said it wasn't
a real issue anyway, and it no longer causes test failures.
Fixes issue #1779871.
........
r61439 | martin.v.loewis | 2008-03-17 17:31:57 +0100 (Mo, 17 Mär 2008) | 2 lines
Add Trent Nelson.
........
r61444 | travis.oliphant | 2008-03-17 18:36:12 +0100 (Mo, 17 Mär 2008) | 1 line
Add necessary headers to back-port new buffer protocol to Python 2.6
........
r61449 | gregory.p.smith | 2008-03-17 19:48:05 +0100 (Mo, 17 Mär 2008) | 8 lines
Force zlib.crc32 and zlib.adler32 to return a signed integer on all platforms
regardless of the native sizeof(long) used in the integer object.
This somewhat odd behavior of returning a signed is maintained in 2.x for
compatibility reasons of always returning an integer rather than a long object.
Fixes Issue1202 for Python 2.6
........
r61450 | neal.norwitz | 2008-03-17 20:02:45 +0100 (Mo, 17 Mär 2008) | 3 lines
Use a buffer large enough to ensure we don't overrun, even if the value
is outside the range we expect.
........
r61453 | steven.bethard | 2008-03-17 20:33:11 +0100 (Mo, 17 Mär 2008) | 1 line
Document unicode.isnumeric() and unicode.isdecimal() (issue2326)
........
r61458 | neal.norwitz | 2008-03-17 21:22:43 +0100 (Mo, 17 Mär 2008) | 5 lines
Issue 2321: reduce memory usage (increase the memory that is returned
to the system) by using pymalloc for the data of unicode objects.
Will backport.
........
r61465 | martin.v.loewis | 2008-03-17 22:55:30 +0100 (Mo, 17 Mär 2008) | 2 lines
Add David Wolever.
........
r61468 | gregory.p.smith | 2008-03-18 01:20:01 +0100 (Di, 18 Mär 2008) | 3 lines
Fix the IOError message text when opening a file with an invalid filename.
Error reported by Ilan Schnell.
........
r61471 | brett.cannon | 2008-03-18 02:00:07 +0100 (Di, 18 Mär 2008) | 2 lines
Convert test_strftime, test_getargs, and test_pep247 to use unittest.
........
r61472 | jeffrey.yasskin | 2008-03-18 02:09:59 +0100 (Di, 18 Mär 2008) | 2 lines
Fix build on platforms that don't have intptr_t. Patch by Joseph Armbruster.
........
r61473 | brett.cannon | 2008-03-18 02:50:25 +0100 (Di, 18 Mär 2008) | 2 lines
Convert test_dummy_threading and test_dbm to unittest.
........
r61474 | brett.cannon | 2008-03-18 02:58:56 +0100 (Di, 18 Mär 2008) | 2 lines
Move test_extcall to doctest.
........
r61480 | brett.cannon | 2008-03-18 04:46:22 +0100 (Di, 18 Mär 2008) | 2 lines
test_errno was a no-op test; now it actually tests things and uses unittest.
........
r61483 | brett.cannon | 2008-03-18 05:09:00 +0100 (Di, 18 Mär 2008) | 3 lines
Remove our implementation of memmove() and strerror(); both are in the C89
standard library.
........
r61484 | brett.cannon | 2008-03-18 05:16:06 +0100 (Di, 18 Mär 2008) | 2 lines
The output directory for tests that compare against stdout is now gone!
........
r61488 | jeffrey.yasskin | 2008-03-18 05:29:35 +0100 (Di, 18 Mär 2008) | 2 lines
Block the "socket.ssl() is deprecated" warning from test_socket_ssl.
........
r61495 | jeffrey.yasskin | 2008-03-18 05:56:06 +0100 (Di, 18 Mär 2008) | 4 lines
Speed test_thread up from 51.328s to 0.081s by reducing its sleep times. We
still sleep at all to make it likely that all threads are active at the same
time.
........
r61496 | jeffrey.yasskin | 2008-03-18 06:12:41 +0100 (Di, 18 Mär 2008) | 4 lines
Speed up test_dict by about 10x by only checking selected dict literal sizes,
instead of every integer from 0 to 400. Exhaustive testing wastes time without
providing enough more assurance that the code is correct.
........
r61498 | neal.norwitz | 2008-03-18 06:20:29 +0100 (Di, 18 Mär 2008) | 1 line
Try increasing the timeout to reduce the flakiness of this test.
........
r61503 | brett.cannon | 2008-03-18 06:43:04 +0100 (Di, 18 Mär 2008) | 2 lines
Improve the error message for a test that failed on the S-390 Debian buildbot.
........
r61504 | jeffrey.yasskin | 2008-03-18 06:45:40 +0100 (Di, 18 Mär 2008) | 3 lines
Add a -S/--slow flag to regrtest to have it print the 10 slowest tests with
their times.
........
r61507 | neal.norwitz | 2008-03-18 07:03:46 +0100 (Di, 18 Mär 2008) | 1 line
Add some info to the failure messages
........
r61509 | trent.nelson | 2008-03-18 08:02:12 +0100 (Di, 18 Mär 2008) | 1 line
Issue 2286: bump up the stack size of the 64-bit debug python_d.exe to 2100000. The default value of 200000 causes a stack overflow at 1965 iterations of r_object() in marshal.c, 35 iterations before the 2000 limit enforced by MAX_MARSHAL_STACK_DEPTH.
........
r61510 | trent.nelson | 2008-03-18 08:32:47 +0100 (Di, 18 Mär 2008) | 5 lines
The behaviour of winsound.Beep() seems to differ between different versions of Windows when there's either:
a) no sound card entirely
b) legacy beep driver has been disabled
c) the legacy beep driver has been uninstalled
Sometimes RuntimeErrors are raised, sometimes they're not. If _have_soundcard() returns False, don't expect winsound.Beep() to raise a RuntimeError, as this clearly isn't the case, as demonstrated by the various Win32 XP buildbots.
........
r61515 | martin.v.loewis | 2008-03-18 13:20:15 +0100 (Di, 18 Mär 2008) | 2 lines
norwitz-amd64 (gentoo) has EREMOTEIO.
........
r61516 | martin.v.loewis | 2008-03-18 13:45:37 +0100 (Di, 18 Mär 2008) | 2 lines
Add more Linux error codes.
........
r61517 | martin.v.loewis | 2008-03-18 14:05:03 +0100 (Di, 18 Mär 2008) | 2 lines
Add WSA errors.
........
r61518 | martin.v.loewis | 2008-03-18 14:16:05 +0100 (Di, 18 Mär 2008) | 2 lines
Note that the stderr output of the test is intentional.
........
2008-03-18 12:15:01 -03:00
|
|
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2007-08-31 06:22:56 -03:00
|
|
|
.. _old-string-formatting:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
``printf``-style String Formatting
|
|
|
|
----------------------------------
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. index::
|
|
|
|
single: formatting, string (%)
|
|
|
|
single: interpolation, string (%)
|
2016-02-12 20:41:37 -04:00
|
|
|
single: string; formatting, printf
|
|
|
|
single: string; interpolation, printf
|
2007-08-15 11:28:22 -03:00
|
|
|
single: printf-style formatting
|
|
|
|
single: sprintf-style formatting
|
|
|
|
single: % formatting
|
|
|
|
single: % interpolation
|
|
|
|
|
2007-08-31 06:22:56 -03:00
|
|
|
.. note::
|
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
The formatting operations described here exhibit a variety of quirks that
|
|
|
|
lead to a number of common errors (such as failing to display tuples and
|
2016-02-12 20:41:37 -04:00
|
|
|
dictionaries correctly). Using the newer :ref:`formatted
|
|
|
|
string literals <f-strings>` or the :meth:`str.format` interface
|
|
|
|
helps avoid these errors. These alternatives also provide more powerful,
|
|
|
|
flexible and extensible approaches to formatting text.
|
2007-08-31 06:22:56 -03:00
|
|
|
|
|
|
|
String objects have one unique built-in operation: the ``%`` operator (modulo).
|
|
|
|
This is also known as the string *formatting* or *interpolation* operator.
|
|
|
|
Given ``format % values`` (where *format* is a string), ``%`` conversion
|
|
|
|
specifications in *format* are replaced with zero or more elements of *values*.
|
2012-08-20 04:14:07 -03:00
|
|
|
The effect is similar to using the :c:func:`sprintf` in the C language.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
If *format* requires a single argument, *values* may be a single non-tuple
|
2011-08-15 08:27:19 -03:00
|
|
|
object. [5]_ Otherwise, *values* must be a tuple with exactly the number of
|
2007-08-15 11:28:22 -03:00
|
|
|
items specified by the format string, or a single mapping object (for example, a
|
|
|
|
dictionary).
|
|
|
|
|
|
|
|
A conversion specifier contains two or more characters and has the following
|
|
|
|
components, which must occur in this order:
|
|
|
|
|
|
|
|
#. The ``'%'`` character, which marks the start of the specifier.
|
|
|
|
|
|
|
|
#. Mapping key (optional), consisting of a parenthesised sequence of characters
|
|
|
|
(for example, ``(somename)``).
|
|
|
|
|
|
|
|
#. Conversion flags (optional), which affect the result of some conversion
|
|
|
|
types.
|
|
|
|
|
|
|
|
#. Minimum field width (optional). If specified as an ``'*'`` (asterisk), the
|
|
|
|
actual width is read from the next element of the tuple in *values*, and the
|
|
|
|
object to convert comes after the minimum field width and optional precision.
|
|
|
|
|
|
|
|
#. Precision (optional), given as a ``'.'`` (dot) followed by the precision. If
|
2011-07-29 03:30:42 -03:00
|
|
|
specified as ``'*'`` (an asterisk), the actual precision is read from the next
|
2007-08-15 11:28:22 -03:00
|
|
|
element of the tuple in *values*, and the value to convert comes after the
|
|
|
|
precision.
|
|
|
|
|
|
|
|
#. Length modifier (optional).
|
|
|
|
|
|
|
|
#. Conversion type.
|
|
|
|
|
|
|
|
When the right argument is a dictionary (or other mapping type), then the
|
|
|
|
formats in the string *must* include a parenthesised mapping key into that
|
|
|
|
dictionary inserted immediately after the ``'%'`` character. The mapping key
|
Merged revisions 61724-61725,61731-61735,61737,61739,61741,61743-61744,61753,61761,61765-61767,61769,61773,61776-61778,61780-61783,61788,61793,61796,61807,61813 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sat, 22 Mar 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 M?\195?\164r 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 M?\195?\164r 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 M?\195?\164r 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 M?\195?\164r 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 M?\195?\164r 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 M?\195?\164r 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 M?\195?\164r 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 M?\195?\164r 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 M?\195?\164r 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 M?\195?\164r 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 M?\195?\164r 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sat, 22 Mar 2008) | 2 lines
Install lib2to3.
................
r61731 | facundo.batista | 2008-03-22 03:45:37 +0100 (Sat, 22 Mar 2008) | 4 lines
Small fix that complicated the test actually when that
test failed.
................
r61732 | alexandre.vassalotti | 2008-03-22 05:08:44 +0100 (Sat, 22 Mar 2008) | 2 lines
Added warning for the removal of 'hotshot' in Py3k.
................
r61733 | georg.brandl | 2008-03-22 11:07:29 +0100 (Sat, 22 Mar 2008) | 4 lines
#1918: document that weak references *to* an object are
cleared before the object's __del__ is called, to ensure that the weak
reference callback (if any) finds the object healthy.
................
r61734 | georg.brandl | 2008-03-22 11:56:23 +0100 (Sat, 22 Mar 2008) | 2 lines
Activate the Sphinx doctest extension and convert howto/functional to use it.
................
r61735 | georg.brandl | 2008-03-22 11:58:38 +0100 (Sat, 22 Mar 2008) | 2 lines
Allow giving source names on the cmdline.
................
r61737 | georg.brandl | 2008-03-22 12:00:48 +0100 (Sat, 22 Mar 2008) | 2 lines
Fixup this HOWTO's doctest blocks so that they can be run with sphinx' doctest builder.
................
r61739 | georg.brandl | 2008-03-22 12:47:10 +0100 (Sat, 22 Mar 2008) | 2 lines
Test decimal.rst doctests as far as possible with sphinx doctest.
................
r61741 | georg.brandl | 2008-03-22 13:04:26 +0100 (Sat, 22 Mar 2008) | 2 lines
Make doctests in re docs usable with sphinx' doctest.
................
r61743 | georg.brandl | 2008-03-22 13:59:37 +0100 (Sat, 22 Mar 2008) | 2 lines
Make more doctests in pprint docs testable.
................
r61744 | georg.brandl | 2008-03-22 14:07:06 +0100 (Sat, 22 Mar 2008) | 2 lines
No need to specify explicit "doctest_block" anymore.
................
r61753 | georg.brandl | 2008-03-22 21:08:43 +0100 (Sat, 22 Mar 2008) | 2 lines
Fix-up syntax problems.
................
r61761 | georg.brandl | 2008-03-22 22:06:20 +0100 (Sat, 22 Mar 2008) | 4 lines
Make collections' doctests executable.
(The <BLANKLINE>s will be stripped from presentation output.)
................
r61765 | georg.brandl | 2008-03-22 22:21:57 +0100 (Sat, 22 Mar 2008) | 2 lines
Test doctests in datetime docs.
................
r61766 | georg.brandl | 2008-03-22 22:26:44 +0100 (Sat, 22 Mar 2008) | 2 lines
Test doctests in operator docs.
................
r61767 | georg.brandl | 2008-03-22 22:38:33 +0100 (Sat, 22 Mar 2008) | 2 lines
Enable doctests in functions.rst. Already found two errors :)
................
r61769 | georg.brandl | 2008-03-22 23:04:10 +0100 (Sat, 22 Mar 2008) | 3 lines
Enable doctest running for several other documents.
We have now over 640 doctests that are run with "make doctest".
................
r61773 | raymond.hettinger | 2008-03-23 01:55:46 +0100 (Sun, 23 Mar 2008) | 1 line
Simplify demo code.
................
r61776 | neal.norwitz | 2008-03-23 04:43:33 +0100 (Sun, 23 Mar 2008) | 7 lines
Try to make this test a little more robust and not fail with:
timeout (10.0025) is more than 2 seconds more than expected (0.001)
I'm assuming this problem is caused by DNS lookup. This change
does a DNS lookup of the hostname before trying to connect, so the time
is not included.
................
r61777 | neal.norwitz | 2008-03-23 05:08:30 +0100 (Sun, 23 Mar 2008) | 1 line
Speed up the test by avoiding socket timeouts.
................
r61778 | neal.norwitz | 2008-03-23 05:43:09 +0100 (Sun, 23 Mar 2008) | 1 line
Skip the epoll test if epoll() does not work
................
r61780 | neal.norwitz | 2008-03-23 06:47:20 +0100 (Sun, 23 Mar 2008) | 1 line
Suppress failure (to avoid a flaky test) if we cannot connect to svn.python.org
................
r61781 | neal.norwitz | 2008-03-23 07:13:25 +0100 (Sun, 23 Mar 2008) | 4 lines
Move itertools before future_builtins since the latter depends on the former.
From a clean build importing future_builtins would fail since itertools
wasn't built yet.
................
r61782 | neal.norwitz | 2008-03-23 07:16:04 +0100 (Sun, 23 Mar 2008) | 1 line
Try to prevent the alarm going off early in tearDown
................
r61783 | neal.norwitz | 2008-03-23 07:19:57 +0100 (Sun, 23 Mar 2008) | 4 lines
Remove compiler warnings (on Alpha at least) about using chars as
array subscripts. Using chars are dangerous b/c they are signed
on some platforms and unsigned on others.
................
r61788 | georg.brandl | 2008-03-23 09:05:30 +0100 (Sun, 23 Mar 2008) | 2 lines
Make the doctests presentation-friendlier.
................
r61793 | amaury.forgeotdarc | 2008-03-23 10:55:29 +0100 (Sun, 23 Mar 2008) | 4 lines
#1477: ur'\U0010FFFF' raised in narrow unicode builds.
Corrected the raw-unicode-escape codec to use UTF-16 surrogates in
this case, just like the unicode-escape codec.
................
r61796 | raymond.hettinger | 2008-03-23 14:32:32 +0100 (Sun, 23 Mar 2008) | 1 line
Issue 1681432: Add triangular distribution the random module.
................
r61807 | raymond.hettinger | 2008-03-23 20:37:53 +0100 (Sun, 23 Mar 2008) | 4 lines
Adopt Nick's suggestion for useful default arguments.
Clean-up floating point issues by adding true division and float constants.
................
r61813 | gregory.p.smith | 2008-03-23 22:04:43 +0100 (Sun, 23 Mar 2008) | 6 lines
Fix gzip to deal with CRC's being signed values in Python 2.x properly and to
read 32bit values as unsigned to start with rather than applying signedness
fixups allover the place afterwards.
This hopefully fixes the test_tarfile failure on the alpha/tru64 buildbot.
................
2008-03-23 18:54:12 -03:00
|
|
|
selects the value to be formatted from the mapping. For example:
|
|
|
|
|
2010-10-17 06:19:03 -03:00
|
|
|
>>> print('%(language)s has %(number)03d quote types.' %
|
|
|
|
... {'language': "Python", "number": 2})
|
2007-08-15 11:28:22 -03:00
|
|
|
Python has 002 quote types.
|
|
|
|
|
|
|
|
In this case no ``*`` specifiers may occur in a format (since they require a
|
|
|
|
sequential parameter list).
|
|
|
|
|
|
|
|
The conversion flag characters are:
|
|
|
|
|
|
|
|
+---------+---------------------------------------------------------------------+
|
|
|
|
| Flag | Meaning |
|
|
|
|
+=========+=====================================================================+
|
|
|
|
| ``'#'`` | The value conversion will use the "alternate form" (where defined |
|
|
|
|
| | below). |
|
|
|
|
+---------+---------------------------------------------------------------------+
|
|
|
|
| ``'0'`` | The conversion will be zero padded for numeric values. |
|
|
|
|
+---------+---------------------------------------------------------------------+
|
|
|
|
| ``'-'`` | The converted value is left adjusted (overrides the ``'0'`` |
|
|
|
|
| | conversion if both are given). |
|
|
|
|
+---------+---------------------------------------------------------------------+
|
|
|
|
| ``' '`` | (a space) A blank should be left before a positive number (or empty |
|
|
|
|
| | string) produced by a signed conversion. |
|
|
|
|
+---------+---------------------------------------------------------------------+
|
|
|
|
| ``'+'`` | A sign character (``'+'`` or ``'-'``) will precede the conversion |
|
|
|
|
| | (overrides a "space" flag). |
|
|
|
|
+---------+---------------------------------------------------------------------+
|
|
|
|
|
|
|
|
A length modifier (``h``, ``l``, or ``L``) may be present, but is ignored as it
|
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r62998 | andrew.kuchling | 2008-05-10 15:51:55 -0400 (Sat, 10 May 2008) | 7 lines
#1858 from Tarek Ziade:
Allow multiple repositories in .pypirc; see http://wiki.python.org/moin/EnhancedPyPI
for discussion.
The patch is slightly revised from Tarek's last patch: I've simplified
the PyPIRCCommand.finalize_options() method to not look at sys.argv.
Tests still pass.
........
r63000 | alexandre.vassalotti | 2008-05-10 15:59:16 -0400 (Sat, 10 May 2008) | 5 lines
Cleaned up io._BytesIO.write().
I am amazed that the old code, for inserting null-bytes, actually
worked. Who wrote that thing? Oh, it is me... doh.
........
r63002 | brett.cannon | 2008-05-10 16:52:01 -0400 (Sat, 10 May 2008) | 2 lines
Revert r62998 as it broke the build (seems distutils.config is missing).
........
r63014 | andrew.kuchling | 2008-05-10 18:12:38 -0400 (Sat, 10 May 2008) | 1 line
#1858: add distutils.config module
........
r63027 | brett.cannon | 2008-05-10 21:09:32 -0400 (Sat, 10 May 2008) | 2 lines
Flesh out the 3.0 deprecation to suggest using the ctypes module.
........
r63028 | skip.montanaro | 2008-05-10 22:59:30 -0400 (Sat, 10 May 2008) | 4 lines
Copied two versions of the example from the interactive session. Delete
one.
........
r63037 | georg.brandl | 2008-05-11 03:02:17 -0400 (Sun, 11 May 2008) | 2 lines
reload() takes the module itself.
........
r63038 | alexandre.vassalotti | 2008-05-11 03:06:04 -0400 (Sun, 11 May 2008) | 4 lines
Added test framework for handling module renames.
Factored the import guard in test_py3kwarn.TestStdlibRemovals into
a context manager, namely test_support.CleanImport.
........
r63039 | georg.brandl | 2008-05-11 03:06:05 -0400 (Sun, 11 May 2008) | 2 lines
#2742: ``''`` is not converted to NULL in getaddrinfo.
........
r63040 | alexandre.vassalotti | 2008-05-11 03:08:12 -0400 (Sun, 11 May 2008) | 2 lines
Fixed typo in a comment of test_support.CleanImport.
........
r63041 | alexandre.vassalotti | 2008-05-11 03:10:25 -0400 (Sun, 11 May 2008) | 2 lines
Removed a dead line of code.
........
r63043 | georg.brandl | 2008-05-11 04:47:53 -0400 (Sun, 11 May 2008) | 2 lines
#2812: document property.getter/setter/deleter.
........
r63049 | georg.brandl | 2008-05-11 05:06:30 -0400 (Sun, 11 May 2008) | 2 lines
#1153769: document PEP 237 changes to string formatting.
........
r63050 | georg.brandl | 2008-05-11 05:11:40 -0400 (Sun, 11 May 2008) | 2 lines
#2809: elaborate str.split docstring a bit.
........
r63051 | georg.brandl | 2008-05-11 06:13:59 -0400 (Sun, 11 May 2008) | 2 lines
Fix typo.
........
r63052 | georg.brandl | 2008-05-11 06:33:27 -0400 (Sun, 11 May 2008) | 2 lines
#2709: clarification.
........
r63053 | georg.brandl | 2008-05-11 06:42:28 -0400 (Sun, 11 May 2008) | 2 lines
#2659: add ``break_on_hyphens`` to TextWrapper.
........
r63057 | georg.brandl | 2008-05-11 06:59:39 -0400 (Sun, 11 May 2008) | 2 lines
#2741: clarification of value range for address_family.
........
r63058 | georg.brandl | 2008-05-11 07:09:35 -0400 (Sun, 11 May 2008) | 2 lines
#2452: timeout is used for all blocking operations.
........
r63059 | andrew.kuchling | 2008-05-11 09:33:56 -0400 (Sun, 11 May 2008) | 2 lines
#1792: Improve performance of marshal.dumps() on large objects by increasing
the size of the buffer more quickly.
........
r63060 | andrew.kuchling | 2008-05-11 10:00:00 -0400 (Sun, 11 May 2008) | 1 line
#1858: re-apply patch for this, adding the missing files
........
r63061 | benjamin.peterson | 2008-05-11 10:13:25 -0400 (Sun, 11 May 2008) | 2 lines
Add the "until" command to pdb
........
r63062 | georg.brandl | 2008-05-11 10:17:13 -0400 (Sun, 11 May 2008) | 2 lines
Add some sentence endings.
........
2008-05-15 21:03:33 -03:00
|
|
|
is not necessary for Python -- so e.g. ``%ld`` is identical to ``%d``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
The conversion types are:
|
|
|
|
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
|
|
|
| Conversion | Meaning | Notes |
|
|
|
|
+============+=====================================================+=======+
|
|
|
|
| ``'d'`` | Signed integer decimal. | |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
|
|
|
| ``'i'`` | Signed integer decimal. | |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r62998 | andrew.kuchling | 2008-05-10 15:51:55 -0400 (Sat, 10 May 2008) | 7 lines
#1858 from Tarek Ziade:
Allow multiple repositories in .pypirc; see http://wiki.python.org/moin/EnhancedPyPI
for discussion.
The patch is slightly revised from Tarek's last patch: I've simplified
the PyPIRCCommand.finalize_options() method to not look at sys.argv.
Tests still pass.
........
r63000 | alexandre.vassalotti | 2008-05-10 15:59:16 -0400 (Sat, 10 May 2008) | 5 lines
Cleaned up io._BytesIO.write().
I am amazed that the old code, for inserting null-bytes, actually
worked. Who wrote that thing? Oh, it is me... doh.
........
r63002 | brett.cannon | 2008-05-10 16:52:01 -0400 (Sat, 10 May 2008) | 2 lines
Revert r62998 as it broke the build (seems distutils.config is missing).
........
r63014 | andrew.kuchling | 2008-05-10 18:12:38 -0400 (Sat, 10 May 2008) | 1 line
#1858: add distutils.config module
........
r63027 | brett.cannon | 2008-05-10 21:09:32 -0400 (Sat, 10 May 2008) | 2 lines
Flesh out the 3.0 deprecation to suggest using the ctypes module.
........
r63028 | skip.montanaro | 2008-05-10 22:59:30 -0400 (Sat, 10 May 2008) | 4 lines
Copied two versions of the example from the interactive session. Delete
one.
........
r63037 | georg.brandl | 2008-05-11 03:02:17 -0400 (Sun, 11 May 2008) | 2 lines
reload() takes the module itself.
........
r63038 | alexandre.vassalotti | 2008-05-11 03:06:04 -0400 (Sun, 11 May 2008) | 4 lines
Added test framework for handling module renames.
Factored the import guard in test_py3kwarn.TestStdlibRemovals into
a context manager, namely test_support.CleanImport.
........
r63039 | georg.brandl | 2008-05-11 03:06:05 -0400 (Sun, 11 May 2008) | 2 lines
#2742: ``''`` is not converted to NULL in getaddrinfo.
........
r63040 | alexandre.vassalotti | 2008-05-11 03:08:12 -0400 (Sun, 11 May 2008) | 2 lines
Fixed typo in a comment of test_support.CleanImport.
........
r63041 | alexandre.vassalotti | 2008-05-11 03:10:25 -0400 (Sun, 11 May 2008) | 2 lines
Removed a dead line of code.
........
r63043 | georg.brandl | 2008-05-11 04:47:53 -0400 (Sun, 11 May 2008) | 2 lines
#2812: document property.getter/setter/deleter.
........
r63049 | georg.brandl | 2008-05-11 05:06:30 -0400 (Sun, 11 May 2008) | 2 lines
#1153769: document PEP 237 changes to string formatting.
........
r63050 | georg.brandl | 2008-05-11 05:11:40 -0400 (Sun, 11 May 2008) | 2 lines
#2809: elaborate str.split docstring a bit.
........
r63051 | georg.brandl | 2008-05-11 06:13:59 -0400 (Sun, 11 May 2008) | 2 lines
Fix typo.
........
r63052 | georg.brandl | 2008-05-11 06:33:27 -0400 (Sun, 11 May 2008) | 2 lines
#2709: clarification.
........
r63053 | georg.brandl | 2008-05-11 06:42:28 -0400 (Sun, 11 May 2008) | 2 lines
#2659: add ``break_on_hyphens`` to TextWrapper.
........
r63057 | georg.brandl | 2008-05-11 06:59:39 -0400 (Sun, 11 May 2008) | 2 lines
#2741: clarification of value range for address_family.
........
r63058 | georg.brandl | 2008-05-11 07:09:35 -0400 (Sun, 11 May 2008) | 2 lines
#2452: timeout is used for all blocking operations.
........
r63059 | andrew.kuchling | 2008-05-11 09:33:56 -0400 (Sun, 11 May 2008) | 2 lines
#1792: Improve performance of marshal.dumps() on large objects by increasing
the size of the buffer more quickly.
........
r63060 | andrew.kuchling | 2008-05-11 10:00:00 -0400 (Sun, 11 May 2008) | 1 line
#1858: re-apply patch for this, adding the missing files
........
r63061 | benjamin.peterson | 2008-05-11 10:13:25 -0400 (Sun, 11 May 2008) | 2 lines
Add the "until" command to pdb
........
r63062 | georg.brandl | 2008-05-11 10:17:13 -0400 (Sun, 11 May 2008) | 2 lines
Add some sentence endings.
........
2008-05-15 21:03:33 -03:00
|
|
|
| ``'o'`` | Signed octal value. | \(1) |
|
2007-08-15 11:28:22 -03:00
|
|
|
+------------+-----------------------------------------------------+-------+
|
2016-12-14 22:37:56 -04:00
|
|
|
| ``'u'`` | Obsolete type -- it is identical to ``'d'``. | \(6) |
|
2007-08-15 11:28:22 -03:00
|
|
|
+------------+-----------------------------------------------------+-------+
|
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r62998 | andrew.kuchling | 2008-05-10 15:51:55 -0400 (Sat, 10 May 2008) | 7 lines
#1858 from Tarek Ziade:
Allow multiple repositories in .pypirc; see http://wiki.python.org/moin/EnhancedPyPI
for discussion.
The patch is slightly revised from Tarek's last patch: I've simplified
the PyPIRCCommand.finalize_options() method to not look at sys.argv.
Tests still pass.
........
r63000 | alexandre.vassalotti | 2008-05-10 15:59:16 -0400 (Sat, 10 May 2008) | 5 lines
Cleaned up io._BytesIO.write().
I am amazed that the old code, for inserting null-bytes, actually
worked. Who wrote that thing? Oh, it is me... doh.
........
r63002 | brett.cannon | 2008-05-10 16:52:01 -0400 (Sat, 10 May 2008) | 2 lines
Revert r62998 as it broke the build (seems distutils.config is missing).
........
r63014 | andrew.kuchling | 2008-05-10 18:12:38 -0400 (Sat, 10 May 2008) | 1 line
#1858: add distutils.config module
........
r63027 | brett.cannon | 2008-05-10 21:09:32 -0400 (Sat, 10 May 2008) | 2 lines
Flesh out the 3.0 deprecation to suggest using the ctypes module.
........
r63028 | skip.montanaro | 2008-05-10 22:59:30 -0400 (Sat, 10 May 2008) | 4 lines
Copied two versions of the example from the interactive session. Delete
one.
........
r63037 | georg.brandl | 2008-05-11 03:02:17 -0400 (Sun, 11 May 2008) | 2 lines
reload() takes the module itself.
........
r63038 | alexandre.vassalotti | 2008-05-11 03:06:04 -0400 (Sun, 11 May 2008) | 4 lines
Added test framework for handling module renames.
Factored the import guard in test_py3kwarn.TestStdlibRemovals into
a context manager, namely test_support.CleanImport.
........
r63039 | georg.brandl | 2008-05-11 03:06:05 -0400 (Sun, 11 May 2008) | 2 lines
#2742: ``''`` is not converted to NULL in getaddrinfo.
........
r63040 | alexandre.vassalotti | 2008-05-11 03:08:12 -0400 (Sun, 11 May 2008) | 2 lines
Fixed typo in a comment of test_support.CleanImport.
........
r63041 | alexandre.vassalotti | 2008-05-11 03:10:25 -0400 (Sun, 11 May 2008) | 2 lines
Removed a dead line of code.
........
r63043 | georg.brandl | 2008-05-11 04:47:53 -0400 (Sun, 11 May 2008) | 2 lines
#2812: document property.getter/setter/deleter.
........
r63049 | georg.brandl | 2008-05-11 05:06:30 -0400 (Sun, 11 May 2008) | 2 lines
#1153769: document PEP 237 changes to string formatting.
........
r63050 | georg.brandl | 2008-05-11 05:11:40 -0400 (Sun, 11 May 2008) | 2 lines
#2809: elaborate str.split docstring a bit.
........
r63051 | georg.brandl | 2008-05-11 06:13:59 -0400 (Sun, 11 May 2008) | 2 lines
Fix typo.
........
r63052 | georg.brandl | 2008-05-11 06:33:27 -0400 (Sun, 11 May 2008) | 2 lines
#2709: clarification.
........
r63053 | georg.brandl | 2008-05-11 06:42:28 -0400 (Sun, 11 May 2008) | 2 lines
#2659: add ``break_on_hyphens`` to TextWrapper.
........
r63057 | georg.brandl | 2008-05-11 06:59:39 -0400 (Sun, 11 May 2008) | 2 lines
#2741: clarification of value range for address_family.
........
r63058 | georg.brandl | 2008-05-11 07:09:35 -0400 (Sun, 11 May 2008) | 2 lines
#2452: timeout is used for all blocking operations.
........
r63059 | andrew.kuchling | 2008-05-11 09:33:56 -0400 (Sun, 11 May 2008) | 2 lines
#1792: Improve performance of marshal.dumps() on large objects by increasing
the size of the buffer more quickly.
........
r63060 | andrew.kuchling | 2008-05-11 10:00:00 -0400 (Sun, 11 May 2008) | 1 line
#1858: re-apply patch for this, adding the missing files
........
r63061 | benjamin.peterson | 2008-05-11 10:13:25 -0400 (Sun, 11 May 2008) | 2 lines
Add the "until" command to pdb
........
r63062 | georg.brandl | 2008-05-11 10:17:13 -0400 (Sun, 11 May 2008) | 2 lines
Add some sentence endings.
........
2008-05-15 21:03:33 -03:00
|
|
|
| ``'x'`` | Signed hexadecimal (lowercase). | \(2) |
|
2007-08-15 11:28:22 -03:00
|
|
|
+------------+-----------------------------------------------------+-------+
|
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r62998 | andrew.kuchling | 2008-05-10 15:51:55 -0400 (Sat, 10 May 2008) | 7 lines
#1858 from Tarek Ziade:
Allow multiple repositories in .pypirc; see http://wiki.python.org/moin/EnhancedPyPI
for discussion.
The patch is slightly revised from Tarek's last patch: I've simplified
the PyPIRCCommand.finalize_options() method to not look at sys.argv.
Tests still pass.
........
r63000 | alexandre.vassalotti | 2008-05-10 15:59:16 -0400 (Sat, 10 May 2008) | 5 lines
Cleaned up io._BytesIO.write().
I am amazed that the old code, for inserting null-bytes, actually
worked. Who wrote that thing? Oh, it is me... doh.
........
r63002 | brett.cannon | 2008-05-10 16:52:01 -0400 (Sat, 10 May 2008) | 2 lines
Revert r62998 as it broke the build (seems distutils.config is missing).
........
r63014 | andrew.kuchling | 2008-05-10 18:12:38 -0400 (Sat, 10 May 2008) | 1 line
#1858: add distutils.config module
........
r63027 | brett.cannon | 2008-05-10 21:09:32 -0400 (Sat, 10 May 2008) | 2 lines
Flesh out the 3.0 deprecation to suggest using the ctypes module.
........
r63028 | skip.montanaro | 2008-05-10 22:59:30 -0400 (Sat, 10 May 2008) | 4 lines
Copied two versions of the example from the interactive session. Delete
one.
........
r63037 | georg.brandl | 2008-05-11 03:02:17 -0400 (Sun, 11 May 2008) | 2 lines
reload() takes the module itself.
........
r63038 | alexandre.vassalotti | 2008-05-11 03:06:04 -0400 (Sun, 11 May 2008) | 4 lines
Added test framework for handling module renames.
Factored the import guard in test_py3kwarn.TestStdlibRemovals into
a context manager, namely test_support.CleanImport.
........
r63039 | georg.brandl | 2008-05-11 03:06:05 -0400 (Sun, 11 May 2008) | 2 lines
#2742: ``''`` is not converted to NULL in getaddrinfo.
........
r63040 | alexandre.vassalotti | 2008-05-11 03:08:12 -0400 (Sun, 11 May 2008) | 2 lines
Fixed typo in a comment of test_support.CleanImport.
........
r63041 | alexandre.vassalotti | 2008-05-11 03:10:25 -0400 (Sun, 11 May 2008) | 2 lines
Removed a dead line of code.
........
r63043 | georg.brandl | 2008-05-11 04:47:53 -0400 (Sun, 11 May 2008) | 2 lines
#2812: document property.getter/setter/deleter.
........
r63049 | georg.brandl | 2008-05-11 05:06:30 -0400 (Sun, 11 May 2008) | 2 lines
#1153769: document PEP 237 changes to string formatting.
........
r63050 | georg.brandl | 2008-05-11 05:11:40 -0400 (Sun, 11 May 2008) | 2 lines
#2809: elaborate str.split docstring a bit.
........
r63051 | georg.brandl | 2008-05-11 06:13:59 -0400 (Sun, 11 May 2008) | 2 lines
Fix typo.
........
r63052 | georg.brandl | 2008-05-11 06:33:27 -0400 (Sun, 11 May 2008) | 2 lines
#2709: clarification.
........
r63053 | georg.brandl | 2008-05-11 06:42:28 -0400 (Sun, 11 May 2008) | 2 lines
#2659: add ``break_on_hyphens`` to TextWrapper.
........
r63057 | georg.brandl | 2008-05-11 06:59:39 -0400 (Sun, 11 May 2008) | 2 lines
#2741: clarification of value range for address_family.
........
r63058 | georg.brandl | 2008-05-11 07:09:35 -0400 (Sun, 11 May 2008) | 2 lines
#2452: timeout is used for all blocking operations.
........
r63059 | andrew.kuchling | 2008-05-11 09:33:56 -0400 (Sun, 11 May 2008) | 2 lines
#1792: Improve performance of marshal.dumps() on large objects by increasing
the size of the buffer more quickly.
........
r63060 | andrew.kuchling | 2008-05-11 10:00:00 -0400 (Sun, 11 May 2008) | 1 line
#1858: re-apply patch for this, adding the missing files
........
r63061 | benjamin.peterson | 2008-05-11 10:13:25 -0400 (Sun, 11 May 2008) | 2 lines
Add the "until" command to pdb
........
r63062 | georg.brandl | 2008-05-11 10:17:13 -0400 (Sun, 11 May 2008) | 2 lines
Add some sentence endings.
........
2008-05-15 21:03:33 -03:00
|
|
|
| ``'X'`` | Signed hexadecimal (uppercase). | \(2) |
|
2007-08-15 11:28:22 -03:00
|
|
|
+------------+-----------------------------------------------------+-------+
|
|
|
|
| ``'e'`` | Floating point exponential format (lowercase). | \(3) |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
|
|
|
| ``'E'`` | Floating point exponential format (uppercase). | \(3) |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
2008-07-17 16:18:29 -03:00
|
|
|
| ``'f'`` | Floating point decimal format. | \(3) |
|
2007-08-15 11:28:22 -03:00
|
|
|
+------------+-----------------------------------------------------+-------+
|
2008-07-17 16:18:29 -03:00
|
|
|
| ``'F'`` | Floating point decimal format. | \(3) |
|
2007-08-15 11:28:22 -03:00
|
|
|
+------------+-----------------------------------------------------+-------+
|
2008-05-06 20:45:46 -03:00
|
|
|
| ``'g'`` | Floating point format. Uses lowercase exponential | \(4) |
|
|
|
|
| | format if exponent is less than -4 or not less than | |
|
|
|
|
| | precision, decimal format otherwise. | |
|
2007-08-15 11:28:22 -03:00
|
|
|
+------------+-----------------------------------------------------+-------+
|
2008-05-06 20:45:46 -03:00
|
|
|
| ``'G'`` | Floating point format. Uses uppercase exponential | \(4) |
|
|
|
|
| | format if exponent is less than -4 or not less than | |
|
|
|
|
| | precision, decimal format otherwise. | |
|
2007-08-15 11:28:22 -03:00
|
|
|
+------------+-----------------------------------------------------+-------+
|
|
|
|
| ``'c'`` | Single character (accepts integer or single | |
|
|
|
|
| | character string). | |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
2009-12-19 19:26:38 -04:00
|
|
|
| ``'r'`` | String (converts any Python object using | \(5) |
|
2007-08-15 11:28:22 -03:00
|
|
|
| | :func:`repr`). | |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
2011-07-29 03:30:42 -03:00
|
|
|
| ``'s'`` | String (converts any Python object using | \(5) |
|
2007-08-15 11:28:22 -03:00
|
|
|
| | :func:`str`). | |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
2011-07-29 03:30:42 -03:00
|
|
|
| ``'a'`` | String (converts any Python object using | \(5) |
|
|
|
|
| | :func:`ascii`). | |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
2007-08-15 11:28:22 -03:00
|
|
|
| ``'%'`` | No argument is converted, results in a ``'%'`` | |
|
|
|
|
| | character in the result. | |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
|
|
|
|
(1)
|
2016-12-10 21:07:29 -04:00
|
|
|
The alternate form causes a leading octal specifier (``'0o'``) to be
|
|
|
|
inserted before the first digit.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
(2)
|
|
|
|
The alternate form causes a leading ``'0x'`` or ``'0X'`` (depending on whether
|
2016-12-10 21:07:29 -04:00
|
|
|
the ``'x'`` or ``'X'`` format was used) to be inserted before the first digit.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
(3)
|
|
|
|
The alternate form causes the result to always contain a decimal point, even if
|
|
|
|
no digits follow it.
|
|
|
|
|
|
|
|
The precision determines the number of digits after the decimal point and
|
|
|
|
defaults to 6.
|
|
|
|
|
|
|
|
(4)
|
|
|
|
The alternate form causes the result to always contain a decimal point, and
|
|
|
|
trailing zeroes are not removed as they would otherwise be.
|
|
|
|
|
|
|
|
The precision determines the number of significant digits before and after the
|
|
|
|
decimal point and defaults to 6.
|
|
|
|
|
|
|
|
(5)
|
2011-07-29 03:30:42 -03:00
|
|
|
If precision is ``N``, the output is truncated to ``N`` characters.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2016-12-14 22:37:56 -04:00
|
|
|
(6)
|
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r62998 | andrew.kuchling | 2008-05-10 15:51:55 -0400 (Sat, 10 May 2008) | 7 lines
#1858 from Tarek Ziade:
Allow multiple repositories in .pypirc; see http://wiki.python.org/moin/EnhancedPyPI
for discussion.
The patch is slightly revised from Tarek's last patch: I've simplified
the PyPIRCCommand.finalize_options() method to not look at sys.argv.
Tests still pass.
........
r63000 | alexandre.vassalotti | 2008-05-10 15:59:16 -0400 (Sat, 10 May 2008) | 5 lines
Cleaned up io._BytesIO.write().
I am amazed that the old code, for inserting null-bytes, actually
worked. Who wrote that thing? Oh, it is me... doh.
........
r63002 | brett.cannon | 2008-05-10 16:52:01 -0400 (Sat, 10 May 2008) | 2 lines
Revert r62998 as it broke the build (seems distutils.config is missing).
........
r63014 | andrew.kuchling | 2008-05-10 18:12:38 -0400 (Sat, 10 May 2008) | 1 line
#1858: add distutils.config module
........
r63027 | brett.cannon | 2008-05-10 21:09:32 -0400 (Sat, 10 May 2008) | 2 lines
Flesh out the 3.0 deprecation to suggest using the ctypes module.
........
r63028 | skip.montanaro | 2008-05-10 22:59:30 -0400 (Sat, 10 May 2008) | 4 lines
Copied two versions of the example from the interactive session. Delete
one.
........
r63037 | georg.brandl | 2008-05-11 03:02:17 -0400 (Sun, 11 May 2008) | 2 lines
reload() takes the module itself.
........
r63038 | alexandre.vassalotti | 2008-05-11 03:06:04 -0400 (Sun, 11 May 2008) | 4 lines
Added test framework for handling module renames.
Factored the import guard in test_py3kwarn.TestStdlibRemovals into
a context manager, namely test_support.CleanImport.
........
r63039 | georg.brandl | 2008-05-11 03:06:05 -0400 (Sun, 11 May 2008) | 2 lines
#2742: ``''`` is not converted to NULL in getaddrinfo.
........
r63040 | alexandre.vassalotti | 2008-05-11 03:08:12 -0400 (Sun, 11 May 2008) | 2 lines
Fixed typo in a comment of test_support.CleanImport.
........
r63041 | alexandre.vassalotti | 2008-05-11 03:10:25 -0400 (Sun, 11 May 2008) | 2 lines
Removed a dead line of code.
........
r63043 | georg.brandl | 2008-05-11 04:47:53 -0400 (Sun, 11 May 2008) | 2 lines
#2812: document property.getter/setter/deleter.
........
r63049 | georg.brandl | 2008-05-11 05:06:30 -0400 (Sun, 11 May 2008) | 2 lines
#1153769: document PEP 237 changes to string formatting.
........
r63050 | georg.brandl | 2008-05-11 05:11:40 -0400 (Sun, 11 May 2008) | 2 lines
#2809: elaborate str.split docstring a bit.
........
r63051 | georg.brandl | 2008-05-11 06:13:59 -0400 (Sun, 11 May 2008) | 2 lines
Fix typo.
........
r63052 | georg.brandl | 2008-05-11 06:33:27 -0400 (Sun, 11 May 2008) | 2 lines
#2709: clarification.
........
r63053 | georg.brandl | 2008-05-11 06:42:28 -0400 (Sun, 11 May 2008) | 2 lines
#2659: add ``break_on_hyphens`` to TextWrapper.
........
r63057 | georg.brandl | 2008-05-11 06:59:39 -0400 (Sun, 11 May 2008) | 2 lines
#2741: clarification of value range for address_family.
........
r63058 | georg.brandl | 2008-05-11 07:09:35 -0400 (Sun, 11 May 2008) | 2 lines
#2452: timeout is used for all blocking operations.
........
r63059 | andrew.kuchling | 2008-05-11 09:33:56 -0400 (Sun, 11 May 2008) | 2 lines
#1792: Improve performance of marshal.dumps() on large objects by increasing
the size of the buffer more quickly.
........
r63060 | andrew.kuchling | 2008-05-11 10:00:00 -0400 (Sun, 11 May 2008) | 1 line
#1858: re-apply patch for this, adding the missing files
........
r63061 | benjamin.peterson | 2008-05-11 10:13:25 -0400 (Sun, 11 May 2008) | 2 lines
Add the "until" command to pdb
........
r63062 | georg.brandl | 2008-05-11 10:17:13 -0400 (Sun, 11 May 2008) | 2 lines
Add some sentence endings.
........
2008-05-15 21:03:33 -03:00
|
|
|
See :pep:`237`.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
Since Python strings have an explicit length, ``%s`` conversions do not assume
|
|
|
|
that ``'\0'`` is the end of the string.
|
|
|
|
|
Merged revisions 59605-59624 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59606 | georg.brandl | 2007-12-29 11:57:00 +0100 (Sat, 29 Dec 2007) | 2 lines
Some cleanup in the docs.
........
r59611 | martin.v.loewis | 2007-12-29 19:49:21 +0100 (Sat, 29 Dec 2007) | 2 lines
Bug #1699: Define _BSD_SOURCE only on OpenBSD.
........
r59612 | raymond.hettinger | 2007-12-29 23:09:34 +0100 (Sat, 29 Dec 2007) | 1 line
Simpler documentation for itertools.tee(). Should be backported.
........
r59613 | raymond.hettinger | 2007-12-29 23:16:24 +0100 (Sat, 29 Dec 2007) | 1 line
Improve docs for itertools.groupby(). The use of xrange(0) to create a unique object is less obvious than object().
........
r59620 | christian.heimes | 2007-12-31 15:47:07 +0100 (Mon, 31 Dec 2007) | 3 lines
Added wininst-9.0.exe executable for VS 2008
Integrated bdist_wininst into PCBuild9 directory
........
r59621 | christian.heimes | 2007-12-31 15:51:18 +0100 (Mon, 31 Dec 2007) | 1 line
Moved PCbuild directory to PC/VS7.1
........
r59622 | christian.heimes | 2007-12-31 15:59:26 +0100 (Mon, 31 Dec 2007) | 1 line
Fix paths for build bot
........
r59623 | christian.heimes | 2007-12-31 16:02:41 +0100 (Mon, 31 Dec 2007) | 1 line
Fix paths for build bot, part 2
........
r59624 | christian.heimes | 2007-12-31 16:18:55 +0100 (Mon, 31 Dec 2007) | 1 line
Renamed PCBuild9 directory to PCBuild
........
2007-12-31 12:14:33 -04:00
|
|
|
.. XXX Examples?
|
|
|
|
|
2009-05-01 12:37:04 -03:00
|
|
|
.. versionchanged:: 3.1
|
|
|
|
``%f`` conversions for numbers whose absolute value is over 1e50 are no
|
|
|
|
longer replaced by ``%g`` conversions.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2012-11-20 21:45:51 -04:00
|
|
|
.. index::
|
|
|
|
single: buffer protocol; binary sequence types
|
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. _binaryseq:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Binary Sequence Types --- :class:`bytes`, :class:`bytearray`, :class:`memoryview`
|
|
|
|
=================================================================================
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. index::
|
|
|
|
object: bytes
|
|
|
|
object: bytearray
|
|
|
|
object: memoryview
|
|
|
|
module: array
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
The core built-in types for manipulating binary data are :class:`bytes` and
|
|
|
|
:class:`bytearray`. They are supported by :class:`memoryview` which uses
|
2012-11-20 21:45:51 -04:00
|
|
|
the :ref:`buffer protocol <bufferobjects>` to access the memory of other
|
|
|
|
binary objects without needing to make a copy.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
The :mod:`array` module supports efficient storage of basic data types like
|
|
|
|
32-bit integers and IEEE754 double-precision floating values.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. _typebytes:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
Bytes Objects
|
|
|
|
-------------
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. index:: object: bytes
|
2010-09-13 18:16:29 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Bytes objects are immutable sequences of single bytes. Since many major
|
|
|
|
binary protocols are based on the ASCII text encoding, bytes objects offer
|
|
|
|
several methods that are only valid when working with ASCII compatible
|
|
|
|
data and are closely related to string objects in a variety of other ways.
|
2010-09-13 18:16:29 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
.. class:: bytes([source[, encoding[, errors]]])
|
|
|
|
|
|
|
|
Firstly, the syntax for bytes literals is largely the same as that for string
|
|
|
|
literals, except that a ``b`` prefix is added:
|
2010-09-13 18:16:29 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
* Single quotes: ``b'still allows embedded "double" quotes'``
|
|
|
|
* Double quotes: ``b"still allows embedded 'single' quotes"``.
|
|
|
|
* Triple quoted: ``b'''3 single quotes'''``, ``b"""3 double quotes"""``
|
2010-09-13 18:16:29 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
Only ASCII characters are permitted in bytes literals (regardless of the
|
|
|
|
declared source code encoding). Any binary values over 127 must be entered
|
|
|
|
into bytes literals using the appropriate escape sequence.
|
2010-09-13 18:16:29 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
As with string literals, bytes literals may also use a ``r`` prefix to disable
|
|
|
|
processing of escape sequences. See :ref:`strings` for more about the various
|
|
|
|
forms of bytes literal, including supported escape sequences.
|
2012-03-22 18:20:21 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
While bytes literals and representations are based on ASCII text, bytes
|
|
|
|
objects actually behave like immutable sequences of integers, with each
|
|
|
|
value in the sequence restricted such that ``0 <= x < 256`` (attempts to
|
|
|
|
violate this restriction will trigger :exc:`ValueError`. This is done
|
|
|
|
deliberately to emphasise that while many binary formats include ASCII based
|
|
|
|
elements and can be usefully manipulated with some text-oriented algorithms,
|
|
|
|
this is not generally the case for arbitrary binary data (blindly applying
|
|
|
|
text processing algorithms to binary data formats that are not ASCII
|
|
|
|
compatible will usually lead to data corruption).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
In addition to the literal forms, bytes objects can be created in a number of
|
|
|
|
other ways:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
* A zero-filled bytes object of a specified length: ``bytes(10)``
|
|
|
|
* From an iterable of integers: ``bytes(range(20))``
|
|
|
|
* Copying existing binary data via the buffer protocol: ``bytes(obj)``
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
Also see the :ref:`bytes <func-bytes>` built-in.
|
2012-08-21 04:42:52 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
Since 2 hexadecimal digits correspond precisely to a single byte, hexadecimal
|
|
|
|
numbers are a commonly used format for describing binary data. Accordingly,
|
|
|
|
the bytes type has an additional class method to read data in that format:
|
2014-08-09 03:14:04 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
.. classmethod:: fromhex(string)
|
2014-08-09 03:14:04 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
This :class:`bytes` class method returns a bytes object, decoding the
|
|
|
|
given string object. The string must contain two hexadecimal digits per
|
|
|
|
byte, with ASCII whitespace being ignored.
|
2014-08-09 03:14:04 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
>>> bytes.fromhex('2Ef0 F1f2 ')
|
|
|
|
b'.\xf0\xf1\xf2'
|
2014-08-09 03:14:04 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
A reverse conversion function exists to transform a bytes object into its
|
|
|
|
hexadecimal representation.
|
2015-04-25 20:22:26 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
.. method:: hex()
|
2015-04-25 20:22:26 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
Return a string object containing two hexadecimal digits for each
|
|
|
|
byte in the instance.
|
2015-04-25 20:22:26 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
>>> b'\xf0\xf1\xf2'.hex()
|
|
|
|
'f0f1f2'
|
2015-04-25 20:22:26 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
.. versionadded:: 3.5
|
2015-04-25 20:22:26 -03:00
|
|
|
|
2014-08-09 03:14:04 -03:00
|
|
|
Since bytes objects are sequences of integers (akin to a tuple), for a bytes
|
|
|
|
object *b*, ``b[0]`` will be an integer, while ``b[0:1]`` will be a bytes
|
|
|
|
object of length 1. (This contrasts with text strings, where both indexing
|
|
|
|
and slicing will produce a string of length 1)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
The representation of bytes objects uses the literal format (``b'...'``)
|
|
|
|
since it is often more useful than e.g. ``bytes([46, 46, 46])``. You can
|
|
|
|
always convert a bytes object into a list of integers using ``list(b)``.
|
2007-08-31 07:15:37 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. note::
|
|
|
|
For Python 2.x users: In the Python 2.x series, a variety of implicit
|
|
|
|
conversions between 8-bit strings (the closest thing 2.x offers to a
|
|
|
|
built-in binary data type) and Unicode strings were permitted. This was a
|
|
|
|
backwards compatibility workaround to account for the fact that Python
|
|
|
|
originally only supported 8-bit text, and Unicode text was a later
|
|
|
|
addition. In Python 3.x, those implicit conversions are gone - conversions
|
|
|
|
between 8-bit binary data and Unicode text must be explicit, and bytes and
|
|
|
|
string objects will always compare unequal.
|
2010-10-02 00:16:04 -03:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. _typebytearray:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Bytearray Objects
|
|
|
|
-----------------
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. index:: object: bytearray
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
:class:`bytearray` objects are a mutable counterpart to :class:`bytes`
|
2017-06-02 01:56:24 -03:00
|
|
|
objects.
|
|
|
|
|
|
|
|
.. class:: bytearray([source[, encoding[, errors]]])
|
|
|
|
|
|
|
|
There is no dedicated literal syntax for bytearray objects, instead
|
|
|
|
they are always created by calling the constructor:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
* Creating an empty instance: ``bytearray()``
|
|
|
|
* Creating a zero-filled instance with a given length: ``bytearray(10)``
|
|
|
|
* From an iterable of integers: ``bytearray(range(20))``
|
|
|
|
* Copying existing binary data via the buffer protocol: ``bytearray(b'Hi!')``
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
As bytearray objects are mutable, they support the
|
|
|
|
:ref:`mutable <typesseq-mutable>` sequence operations in addition to the
|
|
|
|
common bytes and bytearray operations described in :ref:`bytes-methods`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
Also see the :ref:`bytearray <func-bytearray>` built-in.
|
2012-08-21 04:42:52 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
Since 2 hexadecimal digits correspond precisely to a single byte, hexadecimal
|
|
|
|
numbers are a commonly used format for describing binary data. Accordingly,
|
|
|
|
the bytearray type has an additional class method to read data in that format:
|
2014-08-09 03:14:04 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
.. classmethod:: fromhex(string)
|
2014-08-09 03:14:04 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
This :class:`bytearray` class method returns bytearray object, decoding
|
|
|
|
the given string object. The string must contain two hexadecimal digits
|
|
|
|
per byte, with ASCII whitespace being ignored.
|
2014-08-09 03:14:04 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
>>> bytearray.fromhex('2Ef0 F1f2 ')
|
|
|
|
bytearray(b'.\xf0\xf1\xf2')
|
2014-08-09 03:14:04 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
A reverse conversion function exists to transform a bytearray object into its
|
|
|
|
hexadecimal representation.
|
2015-04-25 20:22:26 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
.. method:: hex()
|
2015-04-25 20:22:26 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
Return a string object containing two hexadecimal digits for each
|
|
|
|
byte in the instance.
|
2015-04-25 20:22:26 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
>>> bytearray(b'\xf0\xf1\xf2').hex()
|
|
|
|
'f0f1f2'
|
2015-04-25 20:22:26 -03:00
|
|
|
|
2017-06-02 01:56:24 -03:00
|
|
|
.. versionadded:: 3.5
|
2015-04-25 20:22:26 -03:00
|
|
|
|
2014-08-09 03:14:04 -03:00
|
|
|
Since bytearray objects are sequences of integers (akin to a list), for a
|
|
|
|
bytearray object *b*, ``b[0]`` will be an integer, while ``b[0:1]`` will be
|
|
|
|
a bytearray object of length 1. (This contrasts with text strings, where
|
|
|
|
both indexing and slicing will produce a string of length 1)
|
|
|
|
|
|
|
|
The representation of bytearray objects uses the bytes literal format
|
|
|
|
(``bytearray(b'...')``) since it is often more useful than e.g.
|
|
|
|
``bytearray([46, 46, 46])``. You can always convert a bytearray object into
|
|
|
|
a list of integers using ``list(b)``.
|
|
|
|
|
2007-08-31 07:15:37 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. _bytes-methods:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Bytes and Bytearray Operations
|
|
|
|
------------------------------
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. index:: pair: bytes; methods
|
|
|
|
pair: bytearray; methods
|
2010-04-05 15:56:31 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Both bytes and bytearray objects support the :ref:`common <typesseq-common>`
|
|
|
|
sequence operations. They interoperate not just with operands of the same
|
2014-08-09 03:14:04 -03:00
|
|
|
type, but with any :term:`bytes-like object`. Due to this flexibility, they can be
|
2012-08-20 04:14:07 -03:00
|
|
|
freely mixed in operations without causing errors. However, the return type
|
|
|
|
of the result may depend on the order of operands.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2007-10-23 15:17:00 -03:00
|
|
|
.. note::
|
2007-08-31 07:15:37 -03:00
|
|
|
|
2007-11-22 07:00:28 -04:00
|
|
|
The methods on bytes and bytearray objects don't accept strings as their
|
2007-10-23 15:17:00 -03:00
|
|
|
arguments, just as the methods on strings don't accept bytes as their
|
2012-08-20 04:14:07 -03:00
|
|
|
arguments. For example, you have to write::
|
2007-08-31 07:15:37 -03:00
|
|
|
|
2007-10-23 15:17:00 -03:00
|
|
|
a = "abc"
|
|
|
|
b = a.replace("a", "f")
|
2007-08-31 07:15:37 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
and::
|
2007-08-31 07:15:37 -03:00
|
|
|
|
2007-10-23 15:17:00 -03:00
|
|
|
a = b"abc"
|
|
|
|
b = a.replace(b"a", b"f")
|
2007-08-31 07:15:37 -03:00
|
|
|
|
2014-08-09 03:14:04 -03:00
|
|
|
Some bytes and bytearray operations assume the use of ASCII compatible
|
|
|
|
binary formats, and hence should be avoided when working with arbitrary
|
|
|
|
binary data. These restrictions are covered below.
|
2012-08-20 04:14:07 -03:00
|
|
|
|
|
|
|
.. note::
|
2014-08-09 03:14:04 -03:00
|
|
|
Using these ASCII based operations to manipulate binary data that is not
|
2012-08-20 04:14:07 -03:00
|
|
|
stored in an ASCII based format may lead to data corruption.
|
|
|
|
|
2014-08-09 03:14:04 -03:00
|
|
|
The following methods on bytes and bytearray objects can be used with
|
|
|
|
arbitrary binary data.
|
2012-08-20 04:14:07 -03:00
|
|
|
|
2014-08-09 03:14:04 -03:00
|
|
|
.. method:: bytes.count(sub[, start[, end]])
|
|
|
|
bytearray.count(sub[, start[, end]])
|
|
|
|
|
|
|
|
Return the number of non-overlapping occurrences of subsequence *sub* in
|
|
|
|
the range [*start*, *end*]. Optional arguments *start* and *end* are
|
|
|
|
interpreted as in slice notation.
|
2012-08-20 04:14:07 -03:00
|
|
|
|
2014-08-09 03:14:04 -03:00
|
|
|
The subsequence to search for may be any :term:`bytes-like object` or an
|
|
|
|
integer in the range 0 to 255.
|
|
|
|
|
|
|
|
.. versionchanged:: 3.3
|
|
|
|
Also accept an integer in the range 0 to 255 as the subsequence.
|
2012-08-20 04:14:07 -03:00
|
|
|
|
2007-08-31 07:15:37 -03:00
|
|
|
|
2010-11-07 14:41:46 -04:00
|
|
|
.. method:: bytes.decode(encoding="utf-8", errors="strict")
|
|
|
|
bytearray.decode(encoding="utf-8", errors="strict")
|
2009-05-04 18:01:20 -03:00
|
|
|
|
2010-11-07 14:41:46 -04:00
|
|
|
Return a string decoded from the given bytes. Default encoding is
|
|
|
|
``'utf-8'``. *errors* may be given to set a different
|
2009-05-04 18:01:20 -03:00
|
|
|
error handling scheme. The default for *errors* is ``'strict'``, meaning
|
|
|
|
that encoding errors raise a :exc:`UnicodeError`. Other possible values are
|
|
|
|
``'ignore'``, ``'replace'`` and any other name registered via
|
2015-01-06 10:22:00 -04:00
|
|
|
:func:`codecs.register_error`, see section :ref:`error-handlers`. For a
|
2009-05-04 18:01:20 -03:00
|
|
|
list of possible encodings, see section :ref:`standard-encodings`.
|
|
|
|
|
2014-08-09 03:14:04 -03:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
Passing the *encoding* argument to :class:`str` allows decoding any
|
|
|
|
:term:`bytes-like object` directly, without needing to make a temporary
|
|
|
|
bytes or bytearray object.
|
|
|
|
|
2009-09-18 18:42:35 -03:00
|
|
|
.. versionchanged:: 3.1
|
|
|
|
Added support for keyword arguments.
|
|
|
|
|
2007-08-31 07:15:37 -03:00
|
|
|
|
2014-08-09 03:14:04 -03:00
|
|
|
.. method:: bytes.endswith(suffix[, start[, end]])
|
|
|
|
bytearray.endswith(suffix[, start[, end]])
|
2007-08-31 07:15:37 -03:00
|
|
|
|
2014-08-09 03:14:04 -03:00
|
|
|
Return ``True`` if the binary data ends with the specified *suffix*,
|
|
|
|
otherwise return ``False``. *suffix* can also be a tuple of suffixes to
|
|
|
|
look for. With optional *start*, test beginning at that position. With
|
|
|
|
optional *end*, stop comparing at that position.
|
2007-08-31 07:15:37 -03:00
|
|
|
|
2014-08-09 03:14:04 -03:00
|
|
|
The suffix(es) to search for may be any :term:`bytes-like object`.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.find(sub[, start[, end]])
|
|
|
|
bytearray.find(sub[, start[, end]])
|
|
|
|
|
|
|
|
Return the lowest index in the data where the subsequence *sub* is found,
|
|
|
|
such that *sub* is contained in the slice ``s[start:end]``. Optional
|
|
|
|
arguments *start* and *end* are interpreted as in slice notation. Return
|
|
|
|
``-1`` if *sub* is not found.
|
|
|
|
|
|
|
|
The subsequence to search for may be any :term:`bytes-like object` or an
|
|
|
|
integer in the range 0 to 255.
|
2007-08-31 07:15:37 -03:00
|
|
|
|
2014-08-09 03:14:04 -03:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
The :meth:`~bytes.find` method should be used only if you need to know the
|
|
|
|
position of *sub*. To check if *sub* is a substring or not, use the
|
|
|
|
:keyword:`in` operator::
|
|
|
|
|
|
|
|
>>> b'Py' in b'Python'
|
|
|
|
True
|
|
|
|
|
|
|
|
.. versionchanged:: 3.3
|
|
|
|
Also accept an integer in the range 0 to 255 as the subsequence.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.index(sub[, start[, end]])
|
|
|
|
bytearray.index(sub[, start[, end]])
|
|
|
|
|
|
|
|
Like :meth:`~bytes.find`, but raise :exc:`ValueError` when the
|
|
|
|
subsequence is not found.
|
|
|
|
|
|
|
|
The subsequence to search for may be any :term:`bytes-like object` or an
|
|
|
|
integer in the range 0 to 255.
|
|
|
|
|
|
|
|
.. versionchanged:: 3.3
|
|
|
|
Also accept an integer in the range 0 to 255 as the subsequence.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.join(iterable)
|
|
|
|
bytearray.join(iterable)
|
|
|
|
|
|
|
|
Return a bytes or bytearray object which is the concatenation of the
|
2017-05-31 23:49:01 -03:00
|
|
|
binary data sequences in *iterable*. A :exc:`TypeError` will be raised
|
|
|
|
if there are any values in *iterable* that are not :term:`bytes-like
|
|
|
|
objects <bytes-like object>`, including :class:`str` objects. The
|
|
|
|
separator between elements is the contents of the bytes or
|
|
|
|
bytearray object providing this method.
|
2014-08-09 03:14:04 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. staticmethod:: bytes.maketrans(from, to)
|
|
|
|
bytearray.maketrans(from, to)
|
|
|
|
|
|
|
|
This static method returns a translation table usable for
|
|
|
|
:meth:`bytes.translate` that will map each character in *from* into the
|
|
|
|
character at the same position in *to*; *from* and *to* must both be
|
|
|
|
:term:`bytes-like objects <bytes-like object>` and have the same length.
|
|
|
|
|
|
|
|
.. versionadded:: 3.1
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.partition(sep)
|
|
|
|
bytearray.partition(sep)
|
|
|
|
|
|
|
|
Split the sequence at the first occurrence of *sep*, and return a 3-tuple
|
2017-10-29 07:24:45 -03:00
|
|
|
containing the part before the separator, the separator itself or its
|
|
|
|
bytearray copy, and the part after the separator.
|
|
|
|
If the separator is not found, return a 3-tuple
|
2014-08-09 03:14:04 -03:00
|
|
|
containing a copy of the original sequence, followed by two empty bytes or
|
|
|
|
bytearray objects.
|
|
|
|
|
|
|
|
The separator to search for may be any :term:`bytes-like object`.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.replace(old, new[, count])
|
|
|
|
bytearray.replace(old, new[, count])
|
|
|
|
|
|
|
|
Return a copy of the sequence with all occurrences of subsequence *old*
|
|
|
|
replaced by *new*. If the optional argument *count* is given, only the
|
|
|
|
first *count* occurrences are replaced.
|
|
|
|
|
|
|
|
The subsequence to search for and its replacement may be any
|
|
|
|
:term:`bytes-like object`.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
The bytearray version of this method does *not* operate in place - it
|
|
|
|
always produces a new object, even if no changes were made.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.rfind(sub[, start[, end]])
|
|
|
|
bytearray.rfind(sub[, start[, end]])
|
|
|
|
|
|
|
|
Return the highest index in the sequence where the subsequence *sub* is
|
|
|
|
found, such that *sub* is contained within ``s[start:end]``. Optional
|
|
|
|
arguments *start* and *end* are interpreted as in slice notation. Return
|
|
|
|
``-1`` on failure.
|
|
|
|
|
|
|
|
The subsequence to search for may be any :term:`bytes-like object` or an
|
|
|
|
integer in the range 0 to 255.
|
|
|
|
|
|
|
|
.. versionchanged:: 3.3
|
|
|
|
Also accept an integer in the range 0 to 255 as the subsequence.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.rindex(sub[, start[, end]])
|
|
|
|
bytearray.rindex(sub[, start[, end]])
|
|
|
|
|
|
|
|
Like :meth:`~bytes.rfind` but raises :exc:`ValueError` when the
|
|
|
|
subsequence *sub* is not found.
|
|
|
|
|
|
|
|
The subsequence to search for may be any :term:`bytes-like object` or an
|
|
|
|
integer in the range 0 to 255.
|
|
|
|
|
|
|
|
.. versionchanged:: 3.3
|
|
|
|
Also accept an integer in the range 0 to 255 as the subsequence.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.rpartition(sep)
|
|
|
|
bytearray.rpartition(sep)
|
|
|
|
|
|
|
|
Split the sequence at the last occurrence of *sep*, and return a 3-tuple
|
2017-10-29 07:24:45 -03:00
|
|
|
containing the part before the separator, the separator itself or its
|
|
|
|
bytearray copy, and the part after the separator.
|
|
|
|
If the separator is not found, return a 3-tuple
|
2014-08-09 03:14:04 -03:00
|
|
|
containing a copy of the original sequence, followed by two empty bytes or
|
|
|
|
bytearray objects.
|
|
|
|
|
|
|
|
The separator to search for may be any :term:`bytes-like object`.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.startswith(prefix[, start[, end]])
|
|
|
|
bytearray.startswith(prefix[, start[, end]])
|
|
|
|
|
|
|
|
Return ``True`` if the binary data starts with the specified *prefix*,
|
|
|
|
otherwise return ``False``. *prefix* can also be a tuple of prefixes to
|
|
|
|
look for. With optional *start*, test beginning at that position. With
|
|
|
|
optional *end*, stop comparing at that position.
|
|
|
|
|
|
|
|
The prefix(es) to search for may be any :term:`bytes-like object`.
|
2009-04-12 12:51:51 -03:00
|
|
|
|
2009-01-03 17:18:54 -04:00
|
|
|
|
2016-08-27 05:35:02 -03:00
|
|
|
.. method:: bytes.translate(table, delete=b'')
|
|
|
|
bytearray.translate(table, delete=b'')
|
2007-08-31 07:15:37 -03:00
|
|
|
|
2008-12-27 19:33:20 -04:00
|
|
|
Return a copy of the bytes or bytearray object where all bytes occurring in
|
2014-08-09 03:14:04 -03:00
|
|
|
the optional argument *delete* are removed, and the remaining bytes have
|
|
|
|
been mapped through the given translation table, which must be a bytes
|
|
|
|
object of length 256.
|
2007-08-31 07:15:37 -03:00
|
|
|
|
2014-08-09 03:14:04 -03:00
|
|
|
You can use the :func:`bytes.maketrans` method to create a translation
|
|
|
|
table.
|
2007-08-31 07:15:37 -03:00
|
|
|
|
2008-12-27 19:33:20 -04:00
|
|
|
Set the *table* argument to ``None`` for translations that only delete
|
|
|
|
characters::
|
2007-08-31 07:15:37 -03:00
|
|
|
|
2008-12-27 19:33:20 -04:00
|
|
|
>>> b'read this short text'.translate(None, b'aeiou')
|
|
|
|
b'rd ths shrt txt'
|
2007-08-31 07:15:37 -03:00
|
|
|
|
2016-08-27 05:35:02 -03:00
|
|
|
.. versionchanged:: 3.6
|
|
|
|
*delete* is now supported as a keyword argument.
|
|
|
|
|
2007-08-31 07:15:37 -03:00
|
|
|
|
2014-08-09 03:14:04 -03:00
|
|
|
The following methods on bytes and bytearray objects have default behaviours
|
|
|
|
that assume the use of ASCII compatible binary formats, but can still be used
|
|
|
|
with arbitrary binary data by passing appropriate arguments. Note that all of
|
|
|
|
the bytearray methods in this section do *not* operate in place, and instead
|
|
|
|
produce new objects.
|
2009-04-12 12:51:51 -03:00
|
|
|
|
2014-08-09 03:14:04 -03:00
|
|
|
.. method:: bytes.center(width[, fillbyte])
|
|
|
|
bytearray.center(width[, fillbyte])
|
2009-04-12 12:51:51 -03:00
|
|
|
|
2014-08-09 03:14:04 -03:00
|
|
|
Return a copy of the object centered in a sequence of length *width*.
|
|
|
|
Padding is done using the specified *fillbyte* (default is an ASCII
|
|
|
|
space). For :class:`bytes` objects, the original sequence is returned if
|
|
|
|
*width* is less than or equal to ``len(s)``.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
The bytearray version of this method does *not* operate in place -
|
|
|
|
it always produces a new object, even if no changes were made.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.ljust(width[, fillbyte])
|
|
|
|
bytearray.ljust(width[, fillbyte])
|
|
|
|
|
|
|
|
Return a copy of the object left justified in a sequence of length *width*.
|
|
|
|
Padding is done using the specified *fillbyte* (default is an ASCII
|
|
|
|
space). For :class:`bytes` objects, the original sequence is returned if
|
|
|
|
*width* is less than or equal to ``len(s)``.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
The bytearray version of this method does *not* operate in place -
|
|
|
|
it always produces a new object, even if no changes were made.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.lstrip([chars])
|
|
|
|
bytearray.lstrip([chars])
|
|
|
|
|
|
|
|
Return a copy of the sequence with specified leading bytes removed. The
|
|
|
|
*chars* argument is a binary sequence specifying the set of byte values to
|
|
|
|
be removed - the name refers to the fact this method is usually used with
|
|
|
|
ASCII characters. If omitted or ``None``, the *chars* argument defaults
|
|
|
|
to removing ASCII whitespace. The *chars* argument is not a prefix;
|
|
|
|
rather, all combinations of its values are stripped::
|
|
|
|
|
|
|
|
>>> b' spacious '.lstrip()
|
|
|
|
b'spacious '
|
|
|
|
>>> b'www.example.com'.lstrip(b'cmowz.')
|
|
|
|
b'example.com'
|
|
|
|
|
|
|
|
The binary sequence of byte values to remove may be any
|
|
|
|
:term:`bytes-like object`.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
The bytearray version of this method does *not* operate in place -
|
|
|
|
it always produces a new object, even if no changes were made.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.rjust(width[, fillbyte])
|
|
|
|
bytearray.rjust(width[, fillbyte])
|
|
|
|
|
|
|
|
Return a copy of the object right justified in a sequence of length *width*.
|
|
|
|
Padding is done using the specified *fillbyte* (default is an ASCII
|
|
|
|
space). For :class:`bytes` objects, the original sequence is returned if
|
|
|
|
*width* is less than or equal to ``len(s)``.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
The bytearray version of this method does *not* operate in place -
|
|
|
|
it always produces a new object, even if no changes were made.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.rsplit(sep=None, maxsplit=-1)
|
|
|
|
bytearray.rsplit(sep=None, maxsplit=-1)
|
|
|
|
|
|
|
|
Split the binary sequence into subsequences of the same type, using *sep*
|
|
|
|
as the delimiter string. If *maxsplit* is given, at most *maxsplit* splits
|
|
|
|
are done, the *rightmost* ones. If *sep* is not specified or ``None``,
|
|
|
|
any subsequence consisting solely of ASCII whitespace is a separator.
|
|
|
|
Except for splitting from the right, :meth:`rsplit` behaves like
|
|
|
|
:meth:`split` which is described in detail below.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.rstrip([chars])
|
|
|
|
bytearray.rstrip([chars])
|
|
|
|
|
|
|
|
Return a copy of the sequence with specified trailing bytes removed. The
|
|
|
|
*chars* argument is a binary sequence specifying the set of byte values to
|
|
|
|
be removed - the name refers to the fact this method is usually used with
|
|
|
|
ASCII characters. If omitted or ``None``, the *chars* argument defaults to
|
|
|
|
removing ASCII whitespace. The *chars* argument is not a suffix; rather,
|
|
|
|
all combinations of its values are stripped::
|
|
|
|
|
|
|
|
>>> b' spacious '.rstrip()
|
|
|
|
b' spacious'
|
|
|
|
>>> b'mississippi'.rstrip(b'ipz')
|
|
|
|
b'mississ'
|
|
|
|
|
|
|
|
The binary sequence of byte values to remove may be any
|
|
|
|
:term:`bytes-like object`.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
The bytearray version of this method does *not* operate in place -
|
|
|
|
it always produces a new object, even if no changes were made.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.split(sep=None, maxsplit=-1)
|
|
|
|
bytearray.split(sep=None, maxsplit=-1)
|
|
|
|
|
|
|
|
Split the binary sequence into subsequences of the same type, using *sep*
|
|
|
|
as the delimiter string. If *maxsplit* is given and non-negative, at most
|
|
|
|
*maxsplit* splits are done (thus, the list will have at most ``maxsplit+1``
|
|
|
|
elements). If *maxsplit* is not specified or is ``-1``, then there is no
|
|
|
|
limit on the number of splits (all possible splits are made).
|
|
|
|
|
|
|
|
If *sep* is given, consecutive delimiters are not grouped together and are
|
|
|
|
deemed to delimit empty subsequences (for example, ``b'1,,2'.split(b',')``
|
|
|
|
returns ``[b'1', b'', b'2']``). The *sep* argument may consist of a
|
|
|
|
multibyte sequence (for example, ``b'1<>2<>3'.split(b'<>')`` returns
|
|
|
|
``[b'1', b'2', b'3']``). Splitting an empty sequence with a specified
|
|
|
|
separator returns ``[b'']`` or ``[bytearray(b'')]`` depending on the type
|
|
|
|
of object being split. The *sep* argument may be any
|
|
|
|
:term:`bytes-like object`.
|
|
|
|
|
|
|
|
For example::
|
|
|
|
|
|
|
|
>>> b'1,2,3'.split(b',')
|
|
|
|
[b'1', b'2', b'3']
|
|
|
|
>>> b'1,2,3'.split(b',', maxsplit=1)
|
2014-09-22 23:43:50 -03:00
|
|
|
[b'1', b'2,3']
|
2014-08-09 03:14:04 -03:00
|
|
|
>>> b'1,2,,3,'.split(b',')
|
|
|
|
[b'1', b'2', b'', b'3', b'']
|
|
|
|
|
|
|
|
If *sep* is not specified or is ``None``, a different splitting algorithm
|
|
|
|
is applied: runs of consecutive ASCII whitespace are regarded as a single
|
|
|
|
separator, and the result will contain no empty strings at the start or
|
|
|
|
end if the sequence has leading or trailing whitespace. Consequently,
|
|
|
|
splitting an empty sequence or a sequence consisting solely of ASCII
|
|
|
|
whitespace without a specified separator returns ``[]``.
|
|
|
|
|
|
|
|
For example::
|
|
|
|
|
|
|
|
|
|
|
|
>>> b'1 2 3'.split()
|
|
|
|
[b'1', b'2', b'3']
|
|
|
|
>>> b'1 2 3'.split(maxsplit=1)
|
|
|
|
[b'1', b'2 3']
|
|
|
|
>>> b' 1 2 3 '.split()
|
|
|
|
[b'1', b'2', b'3']
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.strip([chars])
|
|
|
|
bytearray.strip([chars])
|
|
|
|
|
|
|
|
Return a copy of the sequence with specified leading and trailing bytes
|
|
|
|
removed. The *chars* argument is a binary sequence specifying the set of
|
|
|
|
byte values to be removed - the name refers to the fact this method is
|
|
|
|
usually used with ASCII characters. If omitted or ``None``, the *chars*
|
|
|
|
argument defaults to removing ASCII whitespace. The *chars* argument is
|
|
|
|
not a prefix or suffix; rather, all combinations of its values are
|
|
|
|
stripped::
|
|
|
|
|
|
|
|
>>> b' spacious '.strip()
|
|
|
|
b'spacious'
|
|
|
|
>>> b'www.example.com'.strip(b'cmowz.')
|
|
|
|
b'example'
|
|
|
|
|
|
|
|
The binary sequence of byte values to remove may be any
|
|
|
|
:term:`bytes-like object`.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
The bytearray version of this method does *not* operate in place -
|
|
|
|
it always produces a new object, even if no changes were made.
|
|
|
|
|
|
|
|
|
|
|
|
The following methods on bytes and bytearray objects assume the use of ASCII
|
|
|
|
compatible binary formats and should not be applied to arbitrary binary data.
|
|
|
|
Note that all of the bytearray methods in this section do *not* operate in
|
|
|
|
place, and instead produce new objects.
|
|
|
|
|
|
|
|
.. method:: bytes.capitalize()
|
|
|
|
bytearray.capitalize()
|
|
|
|
|
|
|
|
Return a copy of the sequence with each byte interpreted as an ASCII
|
|
|
|
character, and the first byte capitalized and the rest lowercased.
|
|
|
|
Non-ASCII byte values are passed through unchanged.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
The bytearray version of this method does *not* operate in place - it
|
|
|
|
always produces a new object, even if no changes were made.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.expandtabs(tabsize=8)
|
|
|
|
bytearray.expandtabs(tabsize=8)
|
|
|
|
|
|
|
|
Return a copy of the sequence where all ASCII tab characters are replaced
|
|
|
|
by one or more ASCII spaces, depending on the current column and the given
|
|
|
|
tab size. Tab positions occur every *tabsize* bytes (default is 8,
|
|
|
|
giving tab positions at columns 0, 8, 16 and so on). To expand the
|
|
|
|
sequence, the current column is set to zero and the sequence is examined
|
|
|
|
byte by byte. If the byte is an ASCII tab character (``b'\t'``), one or
|
|
|
|
more space characters are inserted in the result until the current column
|
|
|
|
is equal to the next tab position. (The tab character itself is not
|
|
|
|
copied.) If the current byte is an ASCII newline (``b'\n'``) or
|
|
|
|
carriage return (``b'\r'``), it is copied and the current column is reset
|
|
|
|
to zero. Any other byte value is copied unchanged and the current column
|
|
|
|
is incremented by one regardless of how the byte value is represented when
|
|
|
|
printed::
|
|
|
|
|
|
|
|
>>> b'01\t012\t0123\t01234'.expandtabs()
|
|
|
|
b'01 012 0123 01234'
|
|
|
|
>>> b'01\t012\t0123\t01234'.expandtabs(4)
|
|
|
|
b'01 012 0123 01234'
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
The bytearray version of this method does *not* operate in place - it
|
|
|
|
always produces a new object, even if no changes were made.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.isalnum()
|
|
|
|
bytearray.isalnum()
|
|
|
|
|
|
|
|
Return true if all bytes in the sequence are alphabetical ASCII characters
|
|
|
|
or ASCII decimal digits and the sequence is not empty, false otherwise.
|
|
|
|
Alphabetic ASCII characters are those byte values in the sequence
|
|
|
|
``b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'``. ASCII decimal
|
|
|
|
digits are those byte values in the sequence ``b'0123456789'``.
|
|
|
|
|
|
|
|
For example::
|
|
|
|
|
|
|
|
>>> b'ABCabc1'.isalnum()
|
|
|
|
True
|
|
|
|
>>> b'ABC abc1'.isalnum()
|
|
|
|
False
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.isalpha()
|
|
|
|
bytearray.isalpha()
|
|
|
|
|
|
|
|
Return true if all bytes in the sequence are alphabetic ASCII characters
|
|
|
|
and the sequence is not empty, false otherwise. Alphabetic ASCII
|
|
|
|
characters are those byte values in the sequence
|
|
|
|
``b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'``.
|
|
|
|
|
|
|
|
For example::
|
|
|
|
|
|
|
|
>>> b'ABCabc'.isalpha()
|
|
|
|
True
|
|
|
|
>>> b'ABCabc1'.isalpha()
|
|
|
|
False
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.isdigit()
|
|
|
|
bytearray.isdigit()
|
|
|
|
|
|
|
|
Return true if all bytes in the sequence are ASCII decimal digits
|
|
|
|
and the sequence is not empty, false otherwise. ASCII decimal digits are
|
|
|
|
those byte values in the sequence ``b'0123456789'``.
|
|
|
|
|
|
|
|
For example::
|
|
|
|
|
|
|
|
>>> b'1234'.isdigit()
|
|
|
|
True
|
|
|
|
>>> b'1.23'.isdigit()
|
|
|
|
False
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.islower()
|
|
|
|
bytearray.islower()
|
|
|
|
|
|
|
|
Return true if there is at least one lowercase ASCII character
|
|
|
|
in the sequence and no uppercase ASCII characters, false otherwise.
|
|
|
|
|
|
|
|
For example::
|
|
|
|
|
|
|
|
>>> b'hello world'.islower()
|
|
|
|
True
|
|
|
|
>>> b'Hello world'.islower()
|
|
|
|
False
|
|
|
|
|
|
|
|
Lowercase ASCII characters are those byte values in the sequence
|
|
|
|
``b'abcdefghijklmnopqrstuvwxyz'``. Uppercase ASCII characters
|
|
|
|
are those byte values in the sequence ``b'ABCDEFGHIJKLMNOPQRSTUVWXYZ'``.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.isspace()
|
|
|
|
bytearray.isspace()
|
|
|
|
|
|
|
|
Return true if all bytes in the sequence are ASCII whitespace and the
|
|
|
|
sequence is not empty, false otherwise. ASCII whitespace characters are
|
2015-11-23 10:43:05 -04:00
|
|
|
those byte values in the sequence ``b' \t\n\r\x0b\f'`` (space, tab, newline,
|
2014-08-09 03:14:04 -03:00
|
|
|
carriage return, vertical tab, form feed).
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.istitle()
|
|
|
|
bytearray.istitle()
|
|
|
|
|
|
|
|
Return true if the sequence is ASCII titlecase and the sequence is not
|
|
|
|
empty, false otherwise. See :meth:`bytes.title` for more details on the
|
|
|
|
definition of "titlecase".
|
|
|
|
|
|
|
|
For example::
|
|
|
|
|
|
|
|
>>> b'Hello World'.istitle()
|
|
|
|
True
|
|
|
|
>>> b'Hello world'.istitle()
|
|
|
|
False
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.isupper()
|
|
|
|
bytearray.isupper()
|
|
|
|
|
2015-02-27 03:40:22 -04:00
|
|
|
Return true if there is at least one uppercase alphabetic ASCII character
|
|
|
|
in the sequence and no lowercase ASCII characters, false otherwise.
|
2014-08-09 03:14:04 -03:00
|
|
|
|
|
|
|
For example::
|
|
|
|
|
|
|
|
>>> b'HELLO WORLD'.isupper()
|
|
|
|
True
|
|
|
|
>>> b'Hello world'.isupper()
|
|
|
|
False
|
|
|
|
|
|
|
|
Lowercase ASCII characters are those byte values in the sequence
|
|
|
|
``b'abcdefghijklmnopqrstuvwxyz'``. Uppercase ASCII characters
|
|
|
|
are those byte values in the sequence ``b'ABCDEFGHIJKLMNOPQRSTUVWXYZ'``.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.lower()
|
|
|
|
bytearray.lower()
|
|
|
|
|
|
|
|
Return a copy of the sequence with all the uppercase ASCII characters
|
|
|
|
converted to their corresponding lowercase counterpart.
|
|
|
|
|
|
|
|
For example::
|
|
|
|
|
|
|
|
>>> b'Hello World'.lower()
|
|
|
|
b'hello world'
|
|
|
|
|
|
|
|
Lowercase ASCII characters are those byte values in the sequence
|
|
|
|
``b'abcdefghijklmnopqrstuvwxyz'``. Uppercase ASCII characters
|
|
|
|
are those byte values in the sequence ``b'ABCDEFGHIJKLMNOPQRSTUVWXYZ'``.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
The bytearray version of this method does *not* operate in place - it
|
|
|
|
always produces a new object, even if no changes were made.
|
|
|
|
|
|
|
|
|
|
|
|
.. index::
|
|
|
|
single: universal newlines; bytes.splitlines method
|
|
|
|
single: universal newlines; bytearray.splitlines method
|
|
|
|
|
|
|
|
.. method:: bytes.splitlines(keepends=False)
|
|
|
|
bytearray.splitlines(keepends=False)
|
|
|
|
|
|
|
|
Return a list of the lines in the binary sequence, breaking at ASCII
|
|
|
|
line boundaries. This method uses the :term:`universal newlines` approach
|
|
|
|
to splitting lines. Line breaks are not included in the resulting list
|
|
|
|
unless *keepends* is given and true.
|
|
|
|
|
|
|
|
For example::
|
|
|
|
|
|
|
|
>>> b'ab c\n\nde fg\rkl\r\n'.splitlines()
|
2014-10-05 23:03:48 -03:00
|
|
|
[b'ab c', b'', b'de fg', b'kl']
|
2014-08-09 03:14:04 -03:00
|
|
|
>>> b'ab c\n\nde fg\rkl\r\n'.splitlines(keepends=True)
|
|
|
|
[b'ab c\n', b'\n', b'de fg\r', b'kl\r\n']
|
|
|
|
|
|
|
|
Unlike :meth:`~bytes.split` when a delimiter string *sep* is given, this
|
|
|
|
method returns an empty list for the empty string, and a terminal line
|
|
|
|
break does not result in an extra line::
|
|
|
|
|
|
|
|
>>> b"".split(b'\n'), b"Two lines\n".split(b'\n')
|
|
|
|
([b''], [b'Two lines', b''])
|
|
|
|
>>> b"".splitlines(), b"One line\n".splitlines()
|
|
|
|
([], [b'One line'])
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.swapcase()
|
|
|
|
bytearray.swapcase()
|
|
|
|
|
|
|
|
Return a copy of the sequence with all the lowercase ASCII characters
|
|
|
|
converted to their corresponding uppercase counterpart and vice-versa.
|
|
|
|
|
|
|
|
For example::
|
|
|
|
|
|
|
|
>>> b'Hello World'.swapcase()
|
|
|
|
b'hELLO wORLD'
|
|
|
|
|
|
|
|
Lowercase ASCII characters are those byte values in the sequence
|
|
|
|
``b'abcdefghijklmnopqrstuvwxyz'``. Uppercase ASCII characters
|
|
|
|
are those byte values in the sequence ``b'ABCDEFGHIJKLMNOPQRSTUVWXYZ'``.
|
|
|
|
|
|
|
|
Unlike :func:`str.swapcase()`, it is always the case that
|
|
|
|
``bin.swapcase().swapcase() == bin`` for the binary versions. Case
|
|
|
|
conversions are symmetrical in ASCII, even though that is not generally
|
|
|
|
true for arbitrary Unicode code points.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
The bytearray version of this method does *not* operate in place - it
|
|
|
|
always produces a new object, even if no changes were made.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.title()
|
|
|
|
bytearray.title()
|
|
|
|
|
|
|
|
Return a titlecased version of the binary sequence where words start with
|
|
|
|
an uppercase ASCII character and the remaining characters are lowercase.
|
|
|
|
Uncased byte values are left unmodified.
|
|
|
|
|
|
|
|
For example::
|
|
|
|
|
|
|
|
>>> b'Hello world'.title()
|
|
|
|
b'Hello World'
|
|
|
|
|
|
|
|
Lowercase ASCII characters are those byte values in the sequence
|
|
|
|
``b'abcdefghijklmnopqrstuvwxyz'``. Uppercase ASCII characters
|
|
|
|
are those byte values in the sequence ``b'ABCDEFGHIJKLMNOPQRSTUVWXYZ'``.
|
|
|
|
All other byte values are uncased.
|
|
|
|
|
|
|
|
The algorithm uses a simple language-independent definition of a word as
|
|
|
|
groups of consecutive letters. The definition works in many contexts but
|
|
|
|
it means that apostrophes in contractions and possessives form word
|
|
|
|
boundaries, which may not be the desired result::
|
|
|
|
|
|
|
|
>>> b"they're bill's friends from the UK".title()
|
|
|
|
b"They'Re Bill'S Friends From The Uk"
|
|
|
|
|
|
|
|
A workaround for apostrophes can be constructed using regular expressions::
|
|
|
|
|
|
|
|
>>> import re
|
|
|
|
>>> def titlecase(s):
|
|
|
|
... return re.sub(rb"[A-Za-z]+('[A-Za-z]+)?",
|
|
|
|
... lambda mo: mo.group(0)[0:1].upper() +
|
|
|
|
... mo.group(0)[1:].lower(),
|
|
|
|
... s)
|
|
|
|
...
|
|
|
|
>>> titlecase(b"they're bill's friends.")
|
|
|
|
b"They're Bill's Friends."
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
The bytearray version of this method does *not* operate in place - it
|
|
|
|
always produces a new object, even if no changes were made.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.upper()
|
|
|
|
bytearray.upper()
|
|
|
|
|
|
|
|
Return a copy of the sequence with all the lowercase ASCII characters
|
|
|
|
converted to their corresponding uppercase counterpart.
|
|
|
|
|
|
|
|
For example::
|
|
|
|
|
|
|
|
>>> b'Hello World'.upper()
|
|
|
|
b'HELLO WORLD'
|
|
|
|
|
|
|
|
Lowercase ASCII characters are those byte values in the sequence
|
|
|
|
``b'abcdefghijklmnopqrstuvwxyz'``. Uppercase ASCII characters
|
|
|
|
are those byte values in the sequence ``b'ABCDEFGHIJKLMNOPQRSTUVWXYZ'``.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
The bytearray version of this method does *not* operate in place - it
|
|
|
|
always produces a new object, even if no changes were made.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: bytes.zfill(width)
|
|
|
|
bytearray.zfill(width)
|
|
|
|
|
|
|
|
Return a copy of the sequence left filled with ASCII ``b'0'`` digits to
|
|
|
|
make a sequence of length *width*. A leading sign prefix (``b'+'``/
|
|
|
|
``b'-'`` is handled by inserting the padding *after* the sign character
|
|
|
|
rather than before. For :class:`bytes` objects, the original sequence is
|
|
|
|
returned if *width* is less than or equal to ``len(seq)``.
|
|
|
|
|
|
|
|
For example::
|
|
|
|
|
|
|
|
>>> b"42".zfill(5)
|
|
|
|
b'00042'
|
|
|
|
>>> b"-42".zfill(5)
|
|
|
|
b'-0042'
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
The bytearray version of this method does *not* operate in place - it
|
|
|
|
always produces a new object, even if no changes were made.
|
2009-04-12 12:51:51 -03:00
|
|
|
|
|
|
|
|
2015-01-24 00:05:18 -04:00
|
|
|
.. _bytes-formatting:
|
|
|
|
|
|
|
|
``printf``-style Bytes Formatting
|
|
|
|
----------------------------------
|
|
|
|
|
|
|
|
.. index::
|
|
|
|
single: formatting, bytes (%)
|
|
|
|
single: formatting, bytearray (%)
|
|
|
|
single: interpolation, bytes (%)
|
|
|
|
single: interpolation, bytearray (%)
|
|
|
|
single: bytes; formatting
|
|
|
|
single: bytearray; formatting
|
|
|
|
single: bytes; interpolation
|
|
|
|
single: bytearray; interpolation
|
|
|
|
single: printf-style formatting
|
|
|
|
single: sprintf-style formatting
|
|
|
|
single: % formatting
|
|
|
|
single: % interpolation
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
The formatting operations described here exhibit a variety of quirks that
|
|
|
|
lead to a number of common errors (such as failing to display tuples and
|
|
|
|
dictionaries correctly). If the value being printed may be a tuple or
|
|
|
|
dictionary, wrap it in a tuple.
|
|
|
|
|
|
|
|
Bytes objects (``bytes``/``bytearray``) have one unique built-in operation:
|
|
|
|
the ``%`` operator (modulo).
|
|
|
|
This is also known as the bytes *formatting* or *interpolation* operator.
|
|
|
|
Given ``format % values`` (where *format* is a bytes object), ``%`` conversion
|
|
|
|
specifications in *format* are replaced with zero or more elements of *values*.
|
|
|
|
The effect is similar to using the :c:func:`sprintf` in the C language.
|
|
|
|
|
|
|
|
If *format* requires a single argument, *values* may be a single non-tuple
|
|
|
|
object. [5]_ Otherwise, *values* must be a tuple with exactly the number of
|
|
|
|
items specified by the format bytes object, or a single mapping object (for
|
|
|
|
example, a dictionary).
|
|
|
|
|
|
|
|
A conversion specifier contains two or more characters and has the following
|
|
|
|
components, which must occur in this order:
|
|
|
|
|
|
|
|
#. The ``'%'`` character, which marks the start of the specifier.
|
|
|
|
|
|
|
|
#. Mapping key (optional), consisting of a parenthesised sequence of characters
|
|
|
|
(for example, ``(somename)``).
|
|
|
|
|
|
|
|
#. Conversion flags (optional), which affect the result of some conversion
|
|
|
|
types.
|
|
|
|
|
|
|
|
#. Minimum field width (optional). If specified as an ``'*'`` (asterisk), the
|
|
|
|
actual width is read from the next element of the tuple in *values*, and the
|
|
|
|
object to convert comes after the minimum field width and optional precision.
|
|
|
|
|
|
|
|
#. Precision (optional), given as a ``'.'`` (dot) followed by the precision. If
|
|
|
|
specified as ``'*'`` (an asterisk), the actual precision is read from the next
|
|
|
|
element of the tuple in *values*, and the value to convert comes after the
|
|
|
|
precision.
|
|
|
|
|
|
|
|
#. Length modifier (optional).
|
|
|
|
|
|
|
|
#. Conversion type.
|
|
|
|
|
|
|
|
When the right argument is a dictionary (or other mapping type), then the
|
|
|
|
formats in the bytes object *must* include a parenthesised mapping key into that
|
|
|
|
dictionary inserted immediately after the ``'%'`` character. The mapping key
|
|
|
|
selects the value to be formatted from the mapping. For example:
|
|
|
|
|
|
|
|
>>> print(b'%(language)s has %(number)03d quote types.' %
|
|
|
|
... {b'language': b"Python", b"number": 2})
|
|
|
|
b'Python has 002 quote types.'
|
|
|
|
|
|
|
|
In this case no ``*`` specifiers may occur in a format (since they require a
|
|
|
|
sequential parameter list).
|
|
|
|
|
|
|
|
The conversion flag characters are:
|
|
|
|
|
|
|
|
+---------+---------------------------------------------------------------------+
|
|
|
|
| Flag | Meaning |
|
|
|
|
+=========+=====================================================================+
|
|
|
|
| ``'#'`` | The value conversion will use the "alternate form" (where defined |
|
|
|
|
| | below). |
|
|
|
|
+---------+---------------------------------------------------------------------+
|
|
|
|
| ``'0'`` | The conversion will be zero padded for numeric values. |
|
|
|
|
+---------+---------------------------------------------------------------------+
|
|
|
|
| ``'-'`` | The converted value is left adjusted (overrides the ``'0'`` |
|
|
|
|
| | conversion if both are given). |
|
|
|
|
+---------+---------------------------------------------------------------------+
|
|
|
|
| ``' '`` | (a space) A blank should be left before a positive number (or empty |
|
|
|
|
| | string) produced by a signed conversion. |
|
|
|
|
+---------+---------------------------------------------------------------------+
|
|
|
|
| ``'+'`` | A sign character (``'+'`` or ``'-'``) will precede the conversion |
|
|
|
|
| | (overrides a "space" flag). |
|
|
|
|
+---------+---------------------------------------------------------------------+
|
|
|
|
|
|
|
|
A length modifier (``h``, ``l``, or ``L``) may be present, but is ignored as it
|
|
|
|
is not necessary for Python -- so e.g. ``%ld`` is identical to ``%d``.
|
|
|
|
|
|
|
|
The conversion types are:
|
|
|
|
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
|
|
|
| Conversion | Meaning | Notes |
|
|
|
|
+============+=====================================================+=======+
|
|
|
|
| ``'d'`` | Signed integer decimal. | |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
|
|
|
| ``'i'`` | Signed integer decimal. | |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
|
|
|
| ``'o'`` | Signed octal value. | \(1) |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
2015-03-11 12:17:00 -03:00
|
|
|
| ``'u'`` | Obsolete type -- it is identical to ``'d'``. | \(8) |
|
2015-01-24 00:05:18 -04:00
|
|
|
+------------+-----------------------------------------------------+-------+
|
|
|
|
| ``'x'`` | Signed hexadecimal (lowercase). | \(2) |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
|
|
|
| ``'X'`` | Signed hexadecimal (uppercase). | \(2) |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
|
|
|
| ``'e'`` | Floating point exponential format (lowercase). | \(3) |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
|
|
|
| ``'E'`` | Floating point exponential format (uppercase). | \(3) |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
|
|
|
| ``'f'`` | Floating point decimal format. | \(3) |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
|
|
|
| ``'F'`` | Floating point decimal format. | \(3) |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
|
|
|
| ``'g'`` | Floating point format. Uses lowercase exponential | \(4) |
|
|
|
|
| | format if exponent is less than -4 or not less than | |
|
|
|
|
| | precision, decimal format otherwise. | |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
|
|
|
| ``'G'`` | Floating point format. Uses uppercase exponential | \(4) |
|
|
|
|
| | format if exponent is less than -4 or not less than | |
|
|
|
|
| | precision, decimal format otherwise. | |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
|
|
|
| ``'c'`` | Single byte (accepts integer or single | |
|
|
|
|
| | byte objects). | |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
|
|
|
| ``'b'`` | Bytes (any object that follows the | \(5) |
|
|
|
|
| | :ref:`buffer protocol <bufferobjects>` or has | |
|
|
|
|
| | :meth:`__bytes__`). | |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
|
|
|
| ``'s'`` | ``'s'`` is an alias for ``'b'`` and should only | \(6) |
|
|
|
|
| | be used for Python2/3 code bases. | |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
|
|
|
| ``'a'`` | Bytes (converts any Python object using | \(5) |
|
|
|
|
| | ``repr(obj).encode('ascii','backslashreplace)``). | |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
2015-03-11 12:17:00 -03:00
|
|
|
| ``'r'`` | ``'r'`` is an alias for ``'a'`` and should only | \(7) |
|
|
|
|
| | be used for Python2/3 code bases. | |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
2015-01-24 00:05:18 -04:00
|
|
|
| ``'%'`` | No argument is converted, results in a ``'%'`` | |
|
|
|
|
| | character in the result. | |
|
|
|
|
+------------+-----------------------------------------------------+-------+
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
|
|
|
|
(1)
|
2016-12-10 21:07:29 -04:00
|
|
|
The alternate form causes a leading octal specifier (``'0o'``) to be
|
|
|
|
inserted before the first digit.
|
2015-01-24 00:05:18 -04:00
|
|
|
|
|
|
|
(2)
|
|
|
|
The alternate form causes a leading ``'0x'`` or ``'0X'`` (depending on whether
|
2016-12-10 21:07:29 -04:00
|
|
|
the ``'x'`` or ``'X'`` format was used) to be inserted before the first digit.
|
2015-01-24 00:05:18 -04:00
|
|
|
|
|
|
|
(3)
|
|
|
|
The alternate form causes the result to always contain a decimal point, even if
|
|
|
|
no digits follow it.
|
|
|
|
|
|
|
|
The precision determines the number of digits after the decimal point and
|
|
|
|
defaults to 6.
|
|
|
|
|
|
|
|
(4)
|
|
|
|
The alternate form causes the result to always contain a decimal point, and
|
|
|
|
trailing zeroes are not removed as they would otherwise be.
|
|
|
|
|
|
|
|
The precision determines the number of significant digits before and after the
|
|
|
|
decimal point and defaults to 6.
|
|
|
|
|
|
|
|
(5)
|
|
|
|
If precision is ``N``, the output is truncated to ``N`` characters.
|
|
|
|
|
|
|
|
(6)
|
|
|
|
``b'%s'`` is deprecated, but will not be removed during the 3.x series.
|
|
|
|
|
|
|
|
(7)
|
2015-03-11 12:17:00 -03:00
|
|
|
``b'%r'`` is deprecated, but will not be removed during the 3.x series.
|
|
|
|
|
|
|
|
(8)
|
2015-01-24 00:05:18 -04:00
|
|
|
See :pep:`237`.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
The bytearray version of this method does *not* operate in place - it
|
|
|
|
always produces a new object, even if no changes were made.
|
|
|
|
|
|
|
|
.. seealso:: :pep:`461`.
|
|
|
|
.. versionadded:: 3.5
|
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. _typememoryview:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Memory Views
|
|
|
|
------------
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
:class:`memoryview` objects allow Python code to access the internal data
|
|
|
|
of an object that supports the :ref:`buffer protocol <bufferobjects>` without
|
|
|
|
copying.
|
2010-03-21 06:10:32 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. class:: memoryview(obj)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Create a :class:`memoryview` that references *obj*. *obj* must support the
|
|
|
|
buffer protocol. Built-in objects that support the buffer protocol include
|
|
|
|
:class:`bytes` and :class:`bytearray`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
A :class:`memoryview` has the notion of an *element*, which is the
|
|
|
|
atomic memory unit handled by the originating object *obj*. For many
|
|
|
|
simple types such as :class:`bytes` and :class:`bytearray`, an element
|
|
|
|
is a single byte, but other types such as :class:`array.array` may have
|
|
|
|
bigger elements.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
``len(view)`` is equal to the length of :class:`~memoryview.tolist`.
|
|
|
|
If ``view.ndim = 0``, the length is 1. If ``view.ndim = 1``, the length
|
|
|
|
is equal to the number of elements in the view. For higher dimensions,
|
|
|
|
the length is equal to the length of the nested list representation of
|
|
|
|
the view. The :class:`~memoryview.itemsize` attribute will give you the
|
|
|
|
number of bytes in a single element.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2015-03-19 19:29:36 -03:00
|
|
|
A :class:`memoryview` supports slicing and indexing to expose its data.
|
|
|
|
One-dimensional slicing will result in a subview::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
>>> v = memoryview(b'abcefg')
|
|
|
|
>>> v[1]
|
|
|
|
98
|
|
|
|
>>> v[-1]
|
|
|
|
103
|
|
|
|
>>> v[1:4]
|
|
|
|
<memory at 0x7f3ddc9f4350>
|
|
|
|
>>> bytes(v[1:4])
|
|
|
|
b'bce'
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2015-03-19 19:29:36 -03:00
|
|
|
If :class:`~memoryview.format` is one of the native format specifiers
|
|
|
|
from the :mod:`struct` module, indexing with an integer or a tuple of
|
|
|
|
integers is also supported and returns a single *element* with
|
|
|
|
the correct type. One-dimensional memoryviews can be indexed
|
|
|
|
with an integer or a one-integer tuple. Multi-dimensional memoryviews
|
|
|
|
can be indexed with tuples of exactly *ndim* integers where *ndim* is
|
|
|
|
the number of dimensions. Zero-dimensional memoryviews can be indexed
|
|
|
|
with the empty tuple.
|
|
|
|
|
|
|
|
Here is an example with a non-byte format::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
>>> import array
|
|
|
|
>>> a = array.array('l', [-11111111, 22222222, -33333333, 44444444])
|
2015-03-19 19:29:36 -03:00
|
|
|
>>> m = memoryview(a)
|
|
|
|
>>> m[0]
|
2012-08-20 04:14:07 -03:00
|
|
|
-11111111
|
2015-03-19 19:29:36 -03:00
|
|
|
>>> m[-1]
|
2012-08-20 04:14:07 -03:00
|
|
|
44444444
|
2015-03-19 19:29:36 -03:00
|
|
|
>>> m[::2].tolist()
|
2012-08-20 04:14:07 -03:00
|
|
|
[-11111111, -33333333]
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2015-03-19 19:29:36 -03:00
|
|
|
If the underlying object is writable, the memoryview supports
|
|
|
|
one-dimensional slice assignment. Resizing is not allowed::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
>>> data = bytearray(b'abcefg')
|
|
|
|
>>> v = memoryview(data)
|
|
|
|
>>> v.readonly
|
|
|
|
False
|
|
|
|
>>> v[0] = ord(b'z')
|
|
|
|
>>> data
|
|
|
|
bytearray(b'zbcefg')
|
|
|
|
>>> v[1:4] = b'123'
|
|
|
|
>>> data
|
|
|
|
bytearray(b'z123fg')
|
|
|
|
>>> v[2:3] = b'spam'
|
|
|
|
Traceback (most recent call last):
|
|
|
|
File "<stdin>", line 1, in <module>
|
|
|
|
ValueError: memoryview assignment: lvalue and rvalue have different structures
|
|
|
|
>>> v[2:6] = b'spam'
|
|
|
|
>>> data
|
|
|
|
bytearray(b'z1spam')
|
Merged revisions 58886-58929 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58892 | guido.van.rossum | 2007-11-06 15:32:56 -0800 (Tue, 06 Nov 2007) | 2 lines
Add missing "return NULL" in overflow check in PyObject_Repr().
........
r58893 | raymond.hettinger | 2007-11-06 17:13:09 -0800 (Tue, 06 Nov 2007) | 1 line
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
........
r58895 | raymond.hettinger | 2007-11-06 18:26:17 -0800 (Tue, 06 Nov 2007) | 1 line
Optimize dict.fromkeys() with dict inputs. Useful for resetting bag/muliset counts for example.
........
r58896 | raymond.hettinger | 2007-11-06 18:45:46 -0800 (Tue, 06 Nov 2007) | 1 line
Add build option for faster loop execution.
........
r58900 | nick.coghlan | 2007-11-07 03:57:51 -0800 (Wed, 07 Nov 2007) | 1 line
Add missing NEWS entry
........
r58905 | christian.heimes | 2007-11-07 09:50:54 -0800 (Wed, 07 Nov 2007) | 1 line
Backported fix for bug #1392 from py3k branch r58903.
........
r58906 | christian.heimes | 2007-11-07 10:30:22 -0800 (Wed, 07 Nov 2007) | 1 line
Backport of Guido's review of my patch.
........
r58908 | raymond.hettinger | 2007-11-07 18:52:43 -0800 (Wed, 07 Nov 2007) | 1 line
Add set.isdisjoint()
........
r58915 | raymond.hettinger | 2007-11-08 10:47:51 -0800 (Thu, 08 Nov 2007) | 1 line
Reposition the decref (spotted by eagle-eye norwitz).
........
r58920 | georg.brandl | 2007-11-09 04:31:43 -0800 (Fri, 09 Nov 2007) | 2 lines
Fix seealso link to sets docs. Do not merge to Py3k.
........
r58921 | georg.brandl | 2007-11-09 05:08:48 -0800 (Fri, 09 Nov 2007) | 2 lines
Fix misleading example.
........
r58923 | georg.brandl | 2007-11-09 09:33:23 -0800 (Fri, 09 Nov 2007) | 3 lines
Correct a comment about testing methods - nowadays most
tests don't run directly on import.
........
r58924 | martin.v.loewis | 2007-11-09 14:56:30 -0800 (Fri, 09 Nov 2007) | 2 lines
Add Amaury Forgeot d'Arc.
........
r58925 | raymond.hettinger | 2007-11-09 15:14:44 -0800 (Fri, 09 Nov 2007) | 1 line
Optimize common case for dict.fromkeys().
........
r58927 | raymond.hettinger | 2007-11-09 17:54:03 -0800 (Fri, 09 Nov 2007) | 1 line
Use a freelist to speed-up block allocation and deallocation in collections.deque().
........
r58929 | guido.van.rossum | 2007-11-10 14:12:24 -0800 (Sat, 10 Nov 2007) | 3 lines
Issue 1416. Add getter, setter, deleter methods to properties that can be
used as decorators to create fully-populated properties.
........
2007-11-10 19:39:45 -04:00
|
|
|
|
2012-09-02 09:50:56 -03:00
|
|
|
One-dimensional memoryviews of hashable (read-only) types with formats
|
|
|
|
'B', 'b' or 'c' are also hashable. The hash is defined as
|
|
|
|
``hash(m) == hash(m.tobytes())``::
|
Merged revisions 58886-58929 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58892 | guido.van.rossum | 2007-11-06 15:32:56 -0800 (Tue, 06 Nov 2007) | 2 lines
Add missing "return NULL" in overflow check in PyObject_Repr().
........
r58893 | raymond.hettinger | 2007-11-06 17:13:09 -0800 (Tue, 06 Nov 2007) | 1 line
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
........
r58895 | raymond.hettinger | 2007-11-06 18:26:17 -0800 (Tue, 06 Nov 2007) | 1 line
Optimize dict.fromkeys() with dict inputs. Useful for resetting bag/muliset counts for example.
........
r58896 | raymond.hettinger | 2007-11-06 18:45:46 -0800 (Tue, 06 Nov 2007) | 1 line
Add build option for faster loop execution.
........
r58900 | nick.coghlan | 2007-11-07 03:57:51 -0800 (Wed, 07 Nov 2007) | 1 line
Add missing NEWS entry
........
r58905 | christian.heimes | 2007-11-07 09:50:54 -0800 (Wed, 07 Nov 2007) | 1 line
Backported fix for bug #1392 from py3k branch r58903.
........
r58906 | christian.heimes | 2007-11-07 10:30:22 -0800 (Wed, 07 Nov 2007) | 1 line
Backport of Guido's review of my patch.
........
r58908 | raymond.hettinger | 2007-11-07 18:52:43 -0800 (Wed, 07 Nov 2007) | 1 line
Add set.isdisjoint()
........
r58915 | raymond.hettinger | 2007-11-08 10:47:51 -0800 (Thu, 08 Nov 2007) | 1 line
Reposition the decref (spotted by eagle-eye norwitz).
........
r58920 | georg.brandl | 2007-11-09 04:31:43 -0800 (Fri, 09 Nov 2007) | 2 lines
Fix seealso link to sets docs. Do not merge to Py3k.
........
r58921 | georg.brandl | 2007-11-09 05:08:48 -0800 (Fri, 09 Nov 2007) | 2 lines
Fix misleading example.
........
r58923 | georg.brandl | 2007-11-09 09:33:23 -0800 (Fri, 09 Nov 2007) | 3 lines
Correct a comment about testing methods - nowadays most
tests don't run directly on import.
........
r58924 | martin.v.loewis | 2007-11-09 14:56:30 -0800 (Fri, 09 Nov 2007) | 2 lines
Add Amaury Forgeot d'Arc.
........
r58925 | raymond.hettinger | 2007-11-09 15:14:44 -0800 (Fri, 09 Nov 2007) | 1 line
Optimize common case for dict.fromkeys().
........
r58927 | raymond.hettinger | 2007-11-09 17:54:03 -0800 (Fri, 09 Nov 2007) | 1 line
Use a freelist to speed-up block allocation and deallocation in collections.deque().
........
r58929 | guido.van.rossum | 2007-11-10 14:12:24 -0800 (Sat, 10 Nov 2007) | 3 lines
Issue 1416. Add getter, setter, deleter methods to properties that can be
used as decorators to create fully-populated properties.
........
2007-11-10 19:39:45 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
>>> v = memoryview(b'abcefg')
|
|
|
|
>>> hash(v) == hash(b'abcefg')
|
|
|
|
True
|
|
|
|
>>> hash(v[2:4]) == hash(b'ce')
|
|
|
|
True
|
|
|
|
>>> hash(v[::-2]) == hash(b'abcefg'[::-2])
|
|
|
|
True
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. versionchanged:: 3.3
|
2015-03-19 19:29:36 -03:00
|
|
|
One-dimensional memoryviews can now be sliced.
|
2012-09-02 09:50:56 -03:00
|
|
|
One-dimensional memoryviews with formats 'B', 'b' or 'c' are now hashable.
|
2007-09-01 12:49:30 -03:00
|
|
|
|
2013-10-02 09:31:47 -03:00
|
|
|
.. versionchanged:: 3.4
|
|
|
|
memoryview is now registered automatically with
|
|
|
|
:class:`collections.abc.Sequence`
|
|
|
|
|
2015-03-19 19:29:36 -03:00
|
|
|
.. versionchanged:: 3.5
|
|
|
|
memoryviews can now be indexed with tuple of integers.
|
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
:class:`memoryview` has several methods:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-25 04:59:50 -03:00
|
|
|
.. method:: __eq__(exporter)
|
|
|
|
|
|
|
|
A memoryview and a :pep:`3118` exporter are equal if their shapes are
|
|
|
|
equivalent and if all corresponding values are equal when the operands'
|
|
|
|
respective format codes are interpreted using :mod:`struct` syntax.
|
|
|
|
|
|
|
|
For the subset of :mod:`struct` format strings currently supported by
|
|
|
|
:meth:`tolist`, ``v`` and ``w`` are equal if ``v.tolist() == w.tolist()``::
|
|
|
|
|
|
|
|
>>> import array
|
|
|
|
>>> a = array.array('I', [1, 2, 3, 4, 5])
|
|
|
|
>>> b = array.array('d', [1.0, 2.0, 3.0, 4.0, 5.0])
|
|
|
|
>>> c = array.array('b', [5, 3, 1])
|
|
|
|
>>> x = memoryview(a)
|
|
|
|
>>> y = memoryview(b)
|
|
|
|
>>> x == a == y == b
|
|
|
|
True
|
|
|
|
>>> x.tolist() == a.tolist() == y.tolist() == b.tolist()
|
|
|
|
True
|
|
|
|
>>> z = y[::-2]
|
|
|
|
>>> z == c
|
|
|
|
True
|
|
|
|
>>> z.tolist() == c.tolist()
|
|
|
|
True
|
|
|
|
|
|
|
|
If either format string is not supported by the :mod:`struct` module,
|
|
|
|
then the objects will always compare as unequal (even if the format
|
|
|
|
strings and buffer contents are identical)::
|
|
|
|
|
|
|
|
>>> from ctypes import BigEndianStructure, c_long
|
|
|
|
>>> class BEPoint(BigEndianStructure):
|
|
|
|
... _fields_ = [("x", c_long), ("y", c_long)]
|
|
|
|
...
|
|
|
|
>>> point = BEPoint(100, 200)
|
|
|
|
>>> a = memoryview(point)
|
|
|
|
>>> b = memoryview(point)
|
|
|
|
>>> a == point
|
|
|
|
False
|
|
|
|
>>> a == b
|
|
|
|
False
|
|
|
|
|
|
|
|
Note that, as with floating point numbers, ``v is w`` does *not* imply
|
|
|
|
``v == w`` for memoryview objects.
|
|
|
|
|
|
|
|
.. versionchanged:: 3.3
|
2012-08-30 07:09:09 -03:00
|
|
|
Previous versions compared the raw memory disregarding the item format
|
|
|
|
and the logical array structure.
|
2012-08-25 04:59:50 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: tobytes()
|
2007-09-01 12:49:30 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Return the data in the buffer as a bytestring. This is equivalent to
|
|
|
|
calling the :class:`bytes` constructor on the memoryview. ::
|
2007-09-01 12:49:30 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
>>> m = memoryview(b"abc")
|
|
|
|
>>> m.tobytes()
|
|
|
|
b'abc'
|
|
|
|
>>> bytes(m)
|
|
|
|
b'abc'
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
For non-contiguous arrays the result is equal to the flattened list
|
2012-08-25 04:59:50 -03:00
|
|
|
representation with all elements converted to bytes. :meth:`tobytes`
|
|
|
|
supports all format strings, including those that are not in
|
|
|
|
:mod:`struct` module syntax.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2015-04-25 20:22:26 -03:00
|
|
|
.. method:: hex()
|
|
|
|
|
|
|
|
Return a string object containing two hexadecimal digits for each
|
|
|
|
byte in the buffer. ::
|
|
|
|
|
|
|
|
>>> m = memoryview(b"abc")
|
|
|
|
>>> m.hex()
|
|
|
|
'616263'
|
|
|
|
|
|
|
|
.. versionadded:: 3.5
|
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: tolist()
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Return the data in the buffer as a list of elements. ::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
>>> memoryview(b'abc').tolist()
|
|
|
|
[97, 98, 99]
|
|
|
|
>>> import array
|
|
|
|
>>> a = array.array('d', [1.1, 2.2, 3.3])
|
|
|
|
>>> m = memoryview(a)
|
|
|
|
>>> m.tolist()
|
|
|
|
[1.1, 2.2, 3.3]
|
Merged revisions 64002-64003,64012,64036-64037,64047,64050-64052,64054-64055,64066,64071 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r64002 | travis.oliphant | 2008-06-07 00:33:21 +0200 (Sat, 07 Jun 2008) | 1 line
Add long double check support to configure test.
........
r64003 | travis.oliphant | 2008-06-07 00:39:47 +0200 (Sat, 07 Jun 2008) | 1 line
Remove locking part of new buffer protocol.
........
r64012 | facundo.batista | 2008-06-07 15:36:36 +0200 (Sat, 07 Jun 2008) | 4 lines
Finished bug #2451. Fixed the retrying part to make it
more robust.
........
r64036 | georg.brandl | 2008-06-08 10:54:40 +0200 (Sun, 08 Jun 2008) | 2 lines
#3028: tokenize passes the physical line.
........
r64037 | georg.brandl | 2008-06-08 10:59:38 +0200 (Sun, 08 Jun 2008) | 2 lines
Argh, I read it wrong. Reverted 64036 and added a clarifying remark.
........
r64047 | raymond.hettinger | 2008-06-09 03:28:30 +0200 (Mon, 09 Jun 2008) | 1 line
Issue3065: Fixed pickling of named tuples. Added tests.
........
r64050 | raymond.hettinger | 2008-06-09 08:54:45 +0200 (Mon, 09 Jun 2008) | 1 line
Issue #2138: Add math.factorial().
........
r64051 | raymond.hettinger | 2008-06-09 10:33:37 +0200 (Mon, 09 Jun 2008) | 1 line
Let set.union() and set.update() accept multiple inputs.
........
r64052 | raymond.hettinger | 2008-06-09 11:29:17 +0200 (Mon, 09 Jun 2008) | 1 line
Address double-rounding scenarios by setting all variables to long doubles.
........
r64054 | raymond.hettinger | 2008-06-09 13:24:47 +0200 (Mon, 09 Jun 2008) | 1 line
Unhappy buildbots. Revert 64052. Long doubles have unexpected effects on some builds.
........
r64055 | raymond.hettinger | 2008-06-09 15:07:27 +0200 (Mon, 09 Jun 2008) | 1 line
Let set.intersection() and set.intersection_update() take multiple input arguments.
........
r64066 | robert.schuppenies | 2008-06-10 12:10:31 +0200 (Tue, 10 Jun 2008) | 2 lines
Issue 3048: Fixed sys.getsizeof for unicode objects.
........
r64071 | thomas.heller | 2008-06-10 16:07:12 +0200 (Tue, 10 Jun 2008) | 3 lines
NEWS entry for:
Add an optional 'offset' parameter to byref, defaulting to zero.
........
2008-06-10 16:20:26 -03:00
|
|
|
|
2012-08-30 07:09:09 -03:00
|
|
|
.. versionchanged:: 3.3
|
|
|
|
:meth:`tolist` now supports all single character native formats in
|
|
|
|
:mod:`struct` module syntax as well as multi-dimensional
|
|
|
|
representations.
|
2012-08-25 04:59:50 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: release()
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Release the underlying buffer exposed by the memoryview object. Many
|
|
|
|
objects take special actions when a view is held on them (for example,
|
|
|
|
a :class:`bytearray` would temporarily forbid resizing); therefore,
|
|
|
|
calling release() is handy to remove these restrictions (and free any
|
|
|
|
dangling resources) as soon as possible.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
After this method has been called, any further operation on the view
|
|
|
|
raises a :class:`ValueError` (except :meth:`release()` itself which can
|
|
|
|
be called multiple times)::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
>>> m = memoryview(b'abc')
|
|
|
|
>>> m.release()
|
|
|
|
>>> m[0]
|
|
|
|
Traceback (most recent call last):
|
|
|
|
File "<stdin>", line 1, in <module>
|
|
|
|
ValueError: operation forbidden on released memoryview object
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
The context management protocol can be used for a similar effect,
|
|
|
|
using the ``with`` statement::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
>>> with memoryview(b'abc') as m:
|
|
|
|
... m[0]
|
|
|
|
...
|
|
|
|
97
|
|
|
|
>>> m[0]
|
|
|
|
Traceback (most recent call last):
|
|
|
|
File "<stdin>", line 1, in <module>
|
|
|
|
ValueError: operation forbidden on released memoryview object
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. versionadded:: 3.2
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: cast(format[, shape])
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Cast a memoryview to a new format or shape. *shape* defaults to
|
|
|
|
``[byte_length//new_itemsize]``, which means that the result view
|
|
|
|
will be one-dimensional. The return value is a new memoryview, but
|
2015-08-08 09:33:28 -03:00
|
|
|
the buffer itself is not copied. Supported casts are 1D -> C-:term:`contiguous`
|
2012-08-25 04:59:50 -03:00
|
|
|
and C-contiguous -> 1D.
|
|
|
|
|
2015-08-08 08:38:10 -03:00
|
|
|
The destination format is restricted to a single element native format in
|
2012-08-25 04:59:50 -03:00
|
|
|
:mod:`struct` syntax. One of the formats must be a byte format
|
2012-08-20 04:14:07 -03:00
|
|
|
('B', 'b' or 'c'). The byte length of the result must be the same
|
|
|
|
as the original length.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Cast 1D/long to 1D/unsigned bytes::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
>>> import array
|
|
|
|
>>> a = array.array('l', [1,2,3])
|
|
|
|
>>> x = memoryview(a)
|
|
|
|
>>> x.format
|
|
|
|
'l'
|
|
|
|
>>> x.itemsize
|
|
|
|
8
|
|
|
|
>>> len(x)
|
|
|
|
3
|
|
|
|
>>> x.nbytes
|
|
|
|
24
|
|
|
|
>>> y = x.cast('B')
|
|
|
|
>>> y.format
|
|
|
|
'B'
|
|
|
|
>>> y.itemsize
|
|
|
|
1
|
|
|
|
>>> len(y)
|
|
|
|
24
|
|
|
|
>>> y.nbytes
|
|
|
|
24
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Cast 1D/unsigned bytes to 1D/char::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
>>> b = bytearray(b'zyz')
|
|
|
|
>>> x = memoryview(b)
|
|
|
|
>>> x[0] = b'a'
|
|
|
|
Traceback (most recent call last):
|
|
|
|
File "<stdin>", line 1, in <module>
|
|
|
|
ValueError: memoryview: invalid value for format "B"
|
|
|
|
>>> y = x.cast('c')
|
|
|
|
>>> y[0] = b'a'
|
|
|
|
>>> b
|
|
|
|
bytearray(b'ayz')
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Cast 1D/bytes to 3D/ints to 1D/signed char::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
>>> import struct
|
|
|
|
>>> buf = struct.pack("i"*12, *list(range(12)))
|
|
|
|
>>> x = memoryview(buf)
|
|
|
|
>>> y = x.cast('i', shape=[2,2,3])
|
|
|
|
>>> y.tolist()
|
|
|
|
[[[0, 1, 2], [3, 4, 5]], [[6, 7, 8], [9, 10, 11]]]
|
|
|
|
>>> y.format
|
|
|
|
'i'
|
|
|
|
>>> y.itemsize
|
|
|
|
4
|
|
|
|
>>> len(y)
|
|
|
|
2
|
|
|
|
>>> y.nbytes
|
|
|
|
48
|
|
|
|
>>> z = y.cast('b')
|
|
|
|
>>> z.format
|
|
|
|
'b'
|
|
|
|
>>> z.itemsize
|
|
|
|
1
|
|
|
|
>>> len(z)
|
|
|
|
48
|
|
|
|
>>> z.nbytes
|
|
|
|
48
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2013-03-11 19:34:00 -03:00
|
|
|
Cast 1D/unsigned char to 2D/unsigned long::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
>>> buf = struct.pack("L"*6, *list(range(6)))
|
|
|
|
>>> x = memoryview(buf)
|
|
|
|
>>> y = x.cast('L', shape=[2,3])
|
|
|
|
>>> len(y)
|
|
|
|
2
|
|
|
|
>>> y.nbytes
|
|
|
|
48
|
|
|
|
>>> y.tolist()
|
|
|
|
[[0, 1, 2], [3, 4, 5]]
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. versionadded:: 3.3
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2015-08-08 08:38:10 -03:00
|
|
|
.. versionchanged:: 3.5
|
|
|
|
The source format is no longer restricted when casting to a byte view.
|
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
There are also several readonly attributes available:
|
Merged revisions 64089,64098,64100-64102,64113,64115-64116,64118,64120,64132,64342 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r64089 | armin.ronacher | 2008-06-10 22:37:02 +0200 (mar., 10 juin 2008) | 3 lines
Fix a formatting error in the ast documentation.
........
r64098 | raymond.hettinger | 2008-06-11 02:25:29 +0200 (mer., 11 juin 2008) | 6 lines
Mini-PEP: Simplifying numbers.py
* Convert binary methods in Integral to mixin methods
* Remove three-arg __pow__ as a required method
* Make __int__ the root method instead of __long__.
........
r64100 | raymond.hettinger | 2008-06-11 02:28:51 +0200 (mer., 11 juin 2008) | 1 line
Update numbers doc for the Integral simplification.
........
r64101 | raymond.hettinger | 2008-06-11 02:44:47 +0200 (mer., 11 juin 2008) | 3 lines
Handle the case with zero arguments.
........
r64102 | benjamin.peterson | 2008-06-11 03:31:28 +0200 (mer., 11 juin 2008) | 4 lines
convert test_struct to a unittest thanks to Giampaolo Rodola
I had to disable one test because it was functioning incorrectly, see #1530559
I also removed the debugging prints
........
r64113 | thomas.heller | 2008-06-11 09:10:43 +0200 (mer., 11 juin 2008) | 2 lines
Fix markup.
Document the new 'offset' parameter for the 'ctypes.byref' function.
........
r64115 | raymond.hettinger | 2008-06-11 12:30:54 +0200 (mer., 11 juin 2008) | 1 line
Multi-arg form for set.difference() and set.difference_update().
........
r64116 | raymond.hettinger | 2008-06-11 14:06:49 +0200 (mer., 11 juin 2008) | 1 line
Issue 3051: Let heapq work with either __lt__ or __le__.
........
r64118 | raymond.hettinger | 2008-06-11 14:39:09 +0200 (mer., 11 juin 2008) | 1 line
Optimize previous checkin for heapq.
........
r64120 | raymond.hettinger | 2008-06-11 15:14:50 +0200 (mer., 11 juin 2008) | 1 line
Add test for heapq using both __lt__ and __le__.
........
r64132 | gregory.p.smith | 2008-06-11 20:00:52 +0200 (mer., 11 juin 2008) | 3 lines
Correct an incorrect comment about our #include of stddef.h.
(see Doug Evans' comment on python-dev 2008-06-10)
........
r64342 | guido.van.rossum | 2008-06-17 19:38:02 +0200 (mar., 17 juin 2008) | 3 lines
Roll back Raymond's -r64098 while we think of something better.
(See issue 3056 -- we're close to a resolution but need unittests.)
........
2008-06-17 17:36:03 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. attribute:: obj
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
The underlying object of the memoryview::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
>>> b = bytearray(b'xyz')
|
|
|
|
>>> m = memoryview(b)
|
|
|
|
>>> m.obj is b
|
|
|
|
True
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. versionadded:: 3.3
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. attribute:: nbytes
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
``nbytes == product(shape) * itemsize == len(m.tobytes())``. This is
|
|
|
|
the amount of space in bytes that the array would use in a contiguous
|
|
|
|
representation. It is not necessarily equal to len(m)::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
>>> import array
|
|
|
|
>>> a = array.array('i', [1,2,3,4,5])
|
|
|
|
>>> m = memoryview(a)
|
|
|
|
>>> len(m)
|
|
|
|
5
|
|
|
|
>>> m.nbytes
|
|
|
|
20
|
|
|
|
>>> y = m[::2]
|
|
|
|
>>> len(y)
|
|
|
|
3
|
|
|
|
>>> y.nbytes
|
|
|
|
12
|
|
|
|
>>> len(y.tobytes())
|
|
|
|
12
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Multi-dimensional arrays::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
>>> import struct
|
|
|
|
>>> buf = struct.pack("d"*12, *[1.5*x for x in range(12)])
|
|
|
|
>>> x = memoryview(buf)
|
|
|
|
>>> y = x.cast('d', shape=[3,4])
|
|
|
|
>>> y.tolist()
|
|
|
|
[[0.0, 1.5, 3.0, 4.5], [6.0, 7.5, 9.0, 10.5], [12.0, 13.5, 15.0, 16.5]]
|
|
|
|
>>> len(y)
|
|
|
|
3
|
|
|
|
>>> y.nbytes
|
|
|
|
96
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. versionadded:: 3.3
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. attribute:: readonly
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
A bool indicating whether the memory is read only.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. attribute:: format
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
A string containing the format (in :mod:`struct` module style) for each
|
|
|
|
element in the view. A memoryview can be created from exporters with
|
|
|
|
arbitrary format strings, but some methods (e.g. :meth:`tolist`) are
|
2012-08-25 04:59:50 -03:00
|
|
|
restricted to native single element formats.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-30 07:09:09 -03:00
|
|
|
.. versionchanged:: 3.3
|
|
|
|
format ``'B'`` is now handled according to the struct module syntax.
|
|
|
|
This means that ``memoryview(b'abc')[0] == b'abc'[0] == 97``.
|
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. attribute:: itemsize
|
Merged revisions 62873,62887,62892-62896,62904 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r62873 | raymond.hettinger | 2008-05-08 12:18:13 -0500 (Thu, 08 May 2008) | 1 line
Issue 2778. Document the temporary frozenset swap in __contains__(), remove(), and discard().
........
r62887 | brett.cannon | 2008-05-08 14:50:51 -0500 (Thu, 08 May 2008) | 5 lines
Make test.test_support.catch_warning() take an argument specifying if any
triggered warnings should be captured. This allows the context manager to be
used to just prevent the internal state of the 'warnings' framework and thus
allow triggered warnings to be displayed.
........
r62892 | brett.cannon | 2008-05-08 15:20:24 -0500 (Thu, 08 May 2008) | 4 lines
Fix a bug introduced by the addition of the 'record' argument to
test.test_support.catch_warning() where showwarning() was not being set
properly.
........
r62893 | brett.cannon | 2008-05-08 15:20:54 -0500 (Thu, 08 May 2008) | 2 lines
Document the 'record' argument for test.test_support.catch_warning().
........
r62894 | brett.cannon | 2008-05-08 15:23:06 -0500 (Thu, 08 May 2008) | 4 lines
Fix sys.flags to properly expose bytes_warning.
Closes issue #2790.
........
r62895 | brett.cannon | 2008-05-08 15:23:54 -0500 (Thu, 08 May 2008) | 2 lines
Add a missing entry on the fix for issue #2790.
........
r62896 | brett.cannon | 2008-05-08 15:24:43 -0500 (Thu, 08 May 2008) | 2 lines
Add test.test_support.catch_warning()'s new argument.
........
r62904 | benjamin.peterson | 2008-05-08 17:09:54 -0500 (Thu, 08 May 2008) | 2 lines
Replace instances of os.path.walk with os.walk
........
2008-05-08 19:27:58 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
The size in bytes of each element of the memoryview::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
>>> import array, struct
|
|
|
|
>>> m = memoryview(array.array('H', [32000, 32001, 32002]))
|
|
|
|
>>> m.itemsize
|
|
|
|
2
|
|
|
|
>>> m[0]
|
|
|
|
32000
|
|
|
|
>>> struct.calcsize('H') == m.itemsize
|
|
|
|
True
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. attribute:: ndim
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
An integer indicating how many dimensions of a multi-dimensional array the
|
|
|
|
memory represents.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. attribute:: shape
|
Merged revisions 58742-58816 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58745 | georg.brandl | 2007-11-01 10:19:33 -0700 (Thu, 01 Nov 2007) | 2 lines
#1364: os.lstat is available on Windows too, as an alias to os.stat.
........
r58750 | christian.heimes | 2007-11-01 12:48:10 -0700 (Thu, 01 Nov 2007) | 1 line
Backport of import tests for bug http://bugs.python.org/issue1293 and bug http://bugs.python.org/issue1342
........
r58751 | christian.heimes | 2007-11-01 13:11:06 -0700 (Thu, 01 Nov 2007) | 1 line
Removed non ASCII text from test as requested by Guido. Sorry :/
........
r58753 | georg.brandl | 2007-11-01 13:37:02 -0700 (Thu, 01 Nov 2007) | 2 lines
Fix markup glitch.
........
r58757 | gregory.p.smith | 2007-11-01 14:08:14 -0700 (Thu, 01 Nov 2007) | 4 lines
Fix bug introduced in revision 58385. Database keys could no longer
have NULL bytes in them. Replace the errant strdup with a
malloc+memcpy. Adds a unit test for the correct behavior.
........
r58758 | gregory.p.smith | 2007-11-01 14:15:36 -0700 (Thu, 01 Nov 2007) | 3 lines
Undo revision 58533 58534 fixes. Those were a workaround for
a problem introduced by 58385.
........
r58759 | gregory.p.smith | 2007-11-01 14:17:47 -0700 (Thu, 01 Nov 2007) | 2 lines
false "fix" undone as correct problem was found and fixed.
........
r58765 | mark.summerfield | 2007-11-02 01:24:59 -0700 (Fri, 02 Nov 2007) | 3 lines
Added more file-handling related cross-references.
........
r58766 | nick.coghlan | 2007-11-02 03:09:12 -0700 (Fri, 02 Nov 2007) | 1 line
Fix for bug 1705170 - contextmanager swallowing StopIteration (2.5 backport candidate)
........
r58784 | thomas.heller | 2007-11-02 12:10:24 -0700 (Fri, 02 Nov 2007) | 4 lines
Issue #1292: On alpha, arm, ppc, and s390 linux systems the
--with-system-ffi configure option defaults to "yes" because the
bundled libffi sources are too old.
........
r58785 | thomas.heller | 2007-11-02 12:11:23 -0700 (Fri, 02 Nov 2007) | 1 line
Enable the full ctypes c_longdouble tests again.
........
r58796 | georg.brandl | 2007-11-02 13:06:17 -0700 (Fri, 02 Nov 2007) | 4 lines
Make "hashable" a glossary entry and clarify docs on __cmp__, __eq__ and __hash__.
I hope the concept of hashability is better understandable now.
Thanks to Tim Hatch for pointing out the flaws here.
........
2007-11-02 20:46:40 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
A tuple of integers the length of :attr:`ndim` giving the shape of the
|
2012-09-03 18:29:22 -03:00
|
|
|
memory as an N-dimensional array.
|
|
|
|
|
|
|
|
.. versionchanged:: 3.3
|
2016-10-19 10:29:26 -03:00
|
|
|
An empty tuple instead of ``None`` when ndim = 0.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. attribute:: strides
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
A tuple of integers the length of :attr:`ndim` giving the size in bytes to
|
|
|
|
access each element for each dimension of the array.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-09-03 18:29:22 -03:00
|
|
|
.. versionchanged:: 3.3
|
2016-10-19 10:29:26 -03:00
|
|
|
An empty tuple instead of ``None`` when ndim = 0.
|
2012-09-03 18:29:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. attribute:: suboffsets
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Used internally for PIL-style arrays. The value is informational only.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. attribute:: c_contiguous
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2015-08-08 09:33:28 -03:00
|
|
|
A bool indicating whether the memory is C-:term:`contiguous`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. versionadded:: 3.3
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. attribute:: f_contiguous
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2015-08-08 09:33:28 -03:00
|
|
|
A bool indicating whether the memory is Fortran :term:`contiguous`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. versionadded:: 3.3
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. attribute:: contiguous
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2015-08-08 09:33:28 -03:00
|
|
|
A bool indicating whether the memory is :term:`contiguous`.
|
2009-01-03 17:18:54 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. versionadded:: 3.3
|
2011-01-08 05:35:38 -04:00
|
|
|
|
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. _types-set:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Set Types --- :class:`set`, :class:`frozenset`
|
|
|
|
==============================================
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. index:: object: set
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
A :dfn:`set` object is an unordered collection of distinct :term:`hashable` objects.
|
|
|
|
Common uses include membership testing, removing duplicates from a sequence, and
|
|
|
|
computing mathematical operations such as intersection, union, difference, and
|
|
|
|
symmetric difference.
|
2012-08-21 04:42:52 -03:00
|
|
|
(For other containers see the built-in :class:`dict`, :class:`list`,
|
2012-08-20 04:14:07 -03:00
|
|
|
and :class:`tuple` classes, and the :mod:`collections` module.)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Like other collections, sets support ``x in set``, ``len(set)``, and ``for x in
|
|
|
|
set``. Being an unordered collection, sets do not record element position or
|
|
|
|
order of insertion. Accordingly, sets do not support indexing, slicing, or
|
|
|
|
other sequence-like behavior.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
There are currently two built-in set types, :class:`set` and :class:`frozenset`.
|
|
|
|
The :class:`set` type is mutable --- the contents can be changed using methods
|
2013-10-09 08:02:31 -03:00
|
|
|
like :meth:`~set.add` and :meth:`~set.remove`. Since it is mutable, it has no
|
|
|
|
hash value and cannot be used as either a dictionary key or as an element of
|
|
|
|
another set. The :class:`frozenset` type is immutable and :term:`hashable` ---
|
|
|
|
its contents cannot be altered after it is created; it can therefore be used as
|
|
|
|
a dictionary key or as an element of another set.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Non-empty sets (not frozensets) can be created by placing a comma-separated list
|
|
|
|
of elements within braces, for example: ``{'jack', 'sjoerd'}``, in addition to the
|
|
|
|
:class:`set` constructor.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
The constructors for both classes work the same:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. class:: set([iterable])
|
|
|
|
frozenset([iterable])
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Return a new set or frozenset object whose elements are taken from
|
2013-04-05 10:21:50 -03:00
|
|
|
*iterable*. The elements of a set must be :term:`hashable`. To
|
|
|
|
represent sets of sets, the inner sets must be :class:`frozenset`
|
|
|
|
objects. If *iterable* is not specified, a new empty set is
|
|
|
|
returned.
|
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r70712 | benjamin.peterson | 2009-03-30 10:15:38 -0500 (Mon, 30 Mar 2009) | 1 line
don't rely on the order dict repr #5605
........
r70714 | brett.cannon | 2009-03-30 10:20:53 -0500 (Mon, 30 Mar 2009) | 1 line
Add an entry to developers.txt.
........
r70764 | martin.v.loewis | 2009-03-30 17:06:33 -0500 (Mon, 30 Mar 2009) | 2 lines
Add several VM developers.
........
r70765 | georg.brandl | 2009-03-30 17:09:34 -0500 (Mon, 30 Mar 2009) | 1 line
#5199: make warning about vars() assignment more visible.
........
r70769 | andrew.kuchling | 2009-03-30 17:29:53 -0500 (Mon, 30 Mar 2009) | 1 line
Remove comment
........
r70770 | andrew.kuchling | 2009-03-30 17:30:20 -0500 (Mon, 30 Mar 2009) | 1 line
Add several items and placeholders
........
r70771 | andrew.kuchling | 2009-03-30 17:31:11 -0500 (Mon, 30 Mar 2009) | 1 line
Many edits
........
r70773 | georg.brandl | 2009-03-30 17:43:00 -0500 (Mon, 30 Mar 2009) | 1 line
#5039: make it clear that the impl. note refers to CPython.
........
r70776 | andrew.kuchling | 2009-03-30 18:08:24 -0500 (Mon, 30 Mar 2009) | 1 line
typo fix
........
r70777 | andrew.kuchling | 2009-03-30 18:09:46 -0500 (Mon, 30 Mar 2009) | 1 line
Add more items
........
r70788 | andrew.kuchling | 2009-03-30 20:21:01 -0500 (Mon, 30 Mar 2009) | 1 line
Add various items
........
r70789 | georg.brandl | 2009-03-30 20:25:15 -0500 (Mon, 30 Mar 2009) | 1 line
Fix a wrong struct field assignment (docstring as closure).
........
r70824 | georg.brandl | 2009-03-31 10:43:20 -0500 (Tue, 31 Mar 2009) | 1 line
#5519: remove reference to Kodos, which seems dead.
........
r70828 | georg.brandl | 2009-03-31 10:50:16 -0500 (Tue, 31 Mar 2009) | 1 line
#5581: fget argument of abstractproperty is optional as well.
........
r70832 | georg.brandl | 2009-03-31 11:31:11 -0500 (Tue, 31 Mar 2009) | 1 line
#1386675: specify WindowsError as the exception, because it has a winerror attribute that EnvironmentError doesnt have.
........
r70836 | georg.brandl | 2009-03-31 11:50:25 -0500 (Tue, 31 Mar 2009) | 1 line
#5417: replace references to undocumented functions by ones to documented functions.
........
r70842 | georg.brandl | 2009-03-31 12:13:06 -0500 (Tue, 31 Mar 2009) | 1 line
#970783: document PyObject_Generic[GS]etAttr.
........
r70851 | georg.brandl | 2009-03-31 13:26:55 -0500 (Tue, 31 Mar 2009) | 1 line
#837577: note cryptic return value of spawn*e on invalid env dicts.
........
r70855 | georg.brandl | 2009-03-31 13:30:37 -0500 (Tue, 31 Mar 2009) | 1 line
#5245: note that PyRun_SimpleString doesnt return on SystemExit.
........
r70857 | georg.brandl | 2009-03-31 13:33:10 -0500 (Tue, 31 Mar 2009) | 1 line
#5227: note that Py_Main doesnt return on SystemExit.
........
r70866 | georg.brandl | 2009-03-31 14:06:57 -0500 (Tue, 31 Mar 2009) | 1 line
#4882: document named group behavior a bit better.
........
r70867 | georg.brandl | 2009-03-31 14:10:35 -0500 (Tue, 31 Mar 2009) | 1 line
#1096310: document usage of sys.__std*__ a bit better.
........
r70868 | georg.brandl | 2009-03-31 14:12:17 -0500 (Tue, 31 Mar 2009) | 1 line
#5190: export make_option in __all__.
........
r70869 | georg.brandl | 2009-03-31 14:14:42 -0500 (Tue, 31 Mar 2009) | 1 line
Fix-up unwanted change.
........
r70870 | georg.brandl | 2009-03-31 14:26:24 -0500 (Tue, 31 Mar 2009) | 1 line
#4411: document mro() and __mro__. (I hope I got it right.)
........
r70871 | georg.brandl | 2009-03-31 14:30:56 -0500 (Tue, 31 Mar 2009) | 1 line
#5618: fix typo.
........
r70872 | r.david.murray | 2009-03-31 14:31:17 -0500 (Tue, 31 Mar 2009) | 3 lines
Delete out-of-date and little-known README from the test
directory by consensus of devs at pycon sprint.
........
r70883 | georg.brandl | 2009-03-31 15:41:08 -0500 (Tue, 31 Mar 2009) | 1 line
#1674032: return value of flag from Event.wait(). OKed by Guido.
........
r70885 | tarek.ziade | 2009-03-31 15:48:31 -0500 (Tue, 31 Mar 2009) | 1 line
using log.warn for sys.stderr
........
r70893 | georg.brandl | 2009-03-31 15:56:32 -0500 (Tue, 31 Mar 2009) | 1 line
#1530012: move TQS section before raw strings.
........
r70894 | benjamin.peterson | 2009-03-31 16:06:30 -0500 (Tue, 31 Mar 2009) | 1 line
take the usual lock precautions around _active_limbo_lock
........
r70896 | georg.brandl | 2009-03-31 16:15:33 -0500 (Tue, 31 Mar 2009) | 1 line
#5598: document DocFileSuite *args argument.
........
r70897 | benjamin.peterson | 2009-03-31 16:34:42 -0500 (Tue, 31 Mar 2009) | 1 line
fix Thread.ident when it is the main thread or a dummy thread #5632
........
r70903 | georg.brandl | 2009-03-31 16:45:18 -0500 (Tue, 31 Mar 2009) | 1 line
#1676135: remove trailing slashes from --prefix argument.
........
r70905 | georg.brandl | 2009-03-31 17:03:40 -0500 (Tue, 31 Mar 2009) | 1 line
#5563: more documentation for bdist_msi.
........
r70906 | georg.brandl | 2009-03-31 17:11:53 -0500 (Tue, 31 Mar 2009) | 1 line
#1651995: fix _convert_ref for non-ASCII characters.
........
r70907 | georg.brandl | 2009-03-31 17:18:19 -0500 (Tue, 31 Mar 2009) | 1 line
#3427: document correct return type for urlopen().info().
........
r70915 | georg.brandl | 2009-03-31 17:40:16 -0500 (Tue, 31 Mar 2009) | 1 line
#5018: remove confusing paragraph.
........
r70927 | georg.brandl | 2009-03-31 18:01:27 -0500 (Tue, 31 Mar 2009) | 1 line
Dont shout to users.
........
r70933 | georg.brandl | 2009-03-31 19:04:33 -0500 (Tue, 31 Mar 2009) | 2 lines
Issue #5635: Fix running test_sys with tracing enabled.
........
r70951 | georg.brandl | 2009-04-01 09:02:27 -0500 (Wed, 01 Apr 2009) | 1 line
Add Maksim, who worked on several issues at the sprint.
........
r70960 | jesse.noller | 2009-04-01 11:42:19 -0500 (Wed, 01 Apr 2009) | 1 line
Issue 3270: document Listener address restrictions on windows
........
r70962 | brett.cannon | 2009-04-01 12:07:16 -0500 (Wed, 01 Apr 2009) | 2 lines
Ron DuPlain was given commit privileges at PyCon 2009 to work on 3to2.
........
r70963 | georg.brandl | 2009-04-01 12:46:01 -0500 (Wed, 01 Apr 2009) | 1 line
#5655: fix docstring oversight.
........
r70964 | brett.cannon | 2009-04-01 12:52:13 -0500 (Wed, 01 Apr 2009) | 2 lines
Paul Kippes was given commit privileges to work on 3to2.
........
r70998 | georg.brandl | 2009-04-01 16:54:21 -0500 (Wed, 01 Apr 2009) | 1 line
In Pdb, stop assigning values to __builtin__._ which interferes with the one commonly installed by gettext.
........
r71001 | brett.cannon | 2009-04-01 18:01:12 -0500 (Wed, 01 Apr 2009) | 3 lines
Add my initials to Misc/developers.txt. Names are now sorted by number of
characters in the person's name.
........
r71006 | georg.brandl | 2009-04-01 18:32:17 -0500 (Wed, 01 Apr 2009) | 1 line
Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
........
r71008 | andrew.kuchling | 2009-04-01 19:02:14 -0500 (Wed, 01 Apr 2009) | 1 line
Typo fix
........
r71010 | benjamin.peterson | 2009-04-01 19:11:52 -0500 (Wed, 01 Apr 2009) | 1 line
fix markup
........
r71011 | benjamin.peterson | 2009-04-01 19:12:47 -0500 (Wed, 01 Apr 2009) | 1 line
this should be :noindex:
........
r71019 | georg.brandl | 2009-04-01 21:00:01 -0500 (Wed, 01 Apr 2009) | 1 line
Fix test_doctest, missed two assignments to curframe.
........
r71037 | r.david.murray | 2009-04-01 23:34:04 -0500 (Wed, 01 Apr 2009) | 6 lines
Clarify that datetime strftime does not produce leap seconds and datetime
strptime does not accept it in the strftime behavior section of the
datetime docs.
Closes issue 2568.
........
r71056 | georg.brandl | 2009-04-02 12:43:07 -0500 (Thu, 02 Apr 2009) | 2 lines
Actually the displayhook should print the repr.
........
r71094 | vinay.sajip | 2009-04-03 05:23:18 -0500 (Fri, 03 Apr 2009) | 1 line
Added warning about logging use from asynchronous signal handlers.
........
r71101 | andrew.kuchling | 2009-04-03 16:43:00 -0500 (Fri, 03 Apr 2009) | 1 line
Add some items
........
r71102 | andrew.kuchling | 2009-04-03 16:44:49 -0500 (Fri, 03 Apr 2009) | 1 line
Fix 'the the'; grammar fix
........
r71103 | andrew.kuchling | 2009-04-03 16:45:29 -0500 (Fri, 03 Apr 2009) | 1 line
Fix 'the the' duplication
........
r71106 | vinay.sajip | 2009-04-03 16:58:16 -0500 (Fri, 03 Apr 2009) | 1 line
Clarified warning about logging use from asynchronous signal handlers.
........
r71119 | raymond.hettinger | 2009-04-04 00:37:47 -0500 (Sat, 04 Apr 2009) | 1 line
Add helpful link.
........
r71123 | r.david.murray | 2009-04-04 01:39:56 -0500 (Sat, 04 Apr 2009) | 2 lines
Fix error in description of 'oct' (issue 5678).
........
r71149 | georg.brandl | 2009-04-04 08:42:39 -0500 (Sat, 04 Apr 2009) | 1 line
#5642: clarify map() compatibility to the builtin.
........
r71150 | georg.brandl | 2009-04-04 08:45:49 -0500 (Sat, 04 Apr 2009) | 1 line
#5601: clarify that webbrowser is not meant for file names.
........
r71203 | benjamin.peterson | 2009-04-04 18:46:34 -0500 (Sat, 04 Apr 2009) | 1 line
note how using iter* are unsafe while mutating and document iter(dict)
........
r71212 | georg.brandl | 2009-04-05 05:24:20 -0500 (Sun, 05 Apr 2009) | 1 line
#1742837: expand HTTP server docs, and fix SocketServer ones to document methods as methods, not functions.
........
r71214 | georg.brandl | 2009-04-05 05:29:57 -0500 (Sun, 05 Apr 2009) | 1 line
Normalize spelling of Mac OS X.
........
r71215 | georg.brandl | 2009-04-05 05:32:26 -0500 (Sun, 05 Apr 2009) | 1 line
Avoid sure signs of a diseased mind.
........
r71216 | georg.brandl | 2009-04-05 05:41:02 -0500 (Sun, 05 Apr 2009) | 1 line
#1718017: document the relation of os.path and the posixpath, ntpath etc. modules better.
........
r71217 | georg.brandl | 2009-04-05 05:48:47 -0500 (Sun, 05 Apr 2009) | 1 line
#1726172: dont raise an unexpected IndexError if a voidresp() call has an empty response.
........
r71221 | vinay.sajip | 2009-04-05 06:06:24 -0500 (Sun, 05 Apr 2009) | 1 line
Issue #5695: Moved logging.captureWarnings() call inside with statement in WarningsTest.test_warnings.
........
r71240 | georg.brandl | 2009-04-05 09:40:06 -0500 (Sun, 05 Apr 2009) | 1 line
#5370: doc update about unpickling objects with custom __getattr__ etc. methods.
........
2009-04-05 16:13:16 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Instances of :class:`set` and :class:`frozenset` provide the following
|
|
|
|
operations:
|
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r70712 | benjamin.peterson | 2009-03-30 10:15:38 -0500 (Mon, 30 Mar 2009) | 1 line
don't rely on the order dict repr #5605
........
r70714 | brett.cannon | 2009-03-30 10:20:53 -0500 (Mon, 30 Mar 2009) | 1 line
Add an entry to developers.txt.
........
r70764 | martin.v.loewis | 2009-03-30 17:06:33 -0500 (Mon, 30 Mar 2009) | 2 lines
Add several VM developers.
........
r70765 | georg.brandl | 2009-03-30 17:09:34 -0500 (Mon, 30 Mar 2009) | 1 line
#5199: make warning about vars() assignment more visible.
........
r70769 | andrew.kuchling | 2009-03-30 17:29:53 -0500 (Mon, 30 Mar 2009) | 1 line
Remove comment
........
r70770 | andrew.kuchling | 2009-03-30 17:30:20 -0500 (Mon, 30 Mar 2009) | 1 line
Add several items and placeholders
........
r70771 | andrew.kuchling | 2009-03-30 17:31:11 -0500 (Mon, 30 Mar 2009) | 1 line
Many edits
........
r70773 | georg.brandl | 2009-03-30 17:43:00 -0500 (Mon, 30 Mar 2009) | 1 line
#5039: make it clear that the impl. note refers to CPython.
........
r70776 | andrew.kuchling | 2009-03-30 18:08:24 -0500 (Mon, 30 Mar 2009) | 1 line
typo fix
........
r70777 | andrew.kuchling | 2009-03-30 18:09:46 -0500 (Mon, 30 Mar 2009) | 1 line
Add more items
........
r70788 | andrew.kuchling | 2009-03-30 20:21:01 -0500 (Mon, 30 Mar 2009) | 1 line
Add various items
........
r70789 | georg.brandl | 2009-03-30 20:25:15 -0500 (Mon, 30 Mar 2009) | 1 line
Fix a wrong struct field assignment (docstring as closure).
........
r70824 | georg.brandl | 2009-03-31 10:43:20 -0500 (Tue, 31 Mar 2009) | 1 line
#5519: remove reference to Kodos, which seems dead.
........
r70828 | georg.brandl | 2009-03-31 10:50:16 -0500 (Tue, 31 Mar 2009) | 1 line
#5581: fget argument of abstractproperty is optional as well.
........
r70832 | georg.brandl | 2009-03-31 11:31:11 -0500 (Tue, 31 Mar 2009) | 1 line
#1386675: specify WindowsError as the exception, because it has a winerror attribute that EnvironmentError doesnt have.
........
r70836 | georg.brandl | 2009-03-31 11:50:25 -0500 (Tue, 31 Mar 2009) | 1 line
#5417: replace references to undocumented functions by ones to documented functions.
........
r70842 | georg.brandl | 2009-03-31 12:13:06 -0500 (Tue, 31 Mar 2009) | 1 line
#970783: document PyObject_Generic[GS]etAttr.
........
r70851 | georg.brandl | 2009-03-31 13:26:55 -0500 (Tue, 31 Mar 2009) | 1 line
#837577: note cryptic return value of spawn*e on invalid env dicts.
........
r70855 | georg.brandl | 2009-03-31 13:30:37 -0500 (Tue, 31 Mar 2009) | 1 line
#5245: note that PyRun_SimpleString doesnt return on SystemExit.
........
r70857 | georg.brandl | 2009-03-31 13:33:10 -0500 (Tue, 31 Mar 2009) | 1 line
#5227: note that Py_Main doesnt return on SystemExit.
........
r70866 | georg.brandl | 2009-03-31 14:06:57 -0500 (Tue, 31 Mar 2009) | 1 line
#4882: document named group behavior a bit better.
........
r70867 | georg.brandl | 2009-03-31 14:10:35 -0500 (Tue, 31 Mar 2009) | 1 line
#1096310: document usage of sys.__std*__ a bit better.
........
r70868 | georg.brandl | 2009-03-31 14:12:17 -0500 (Tue, 31 Mar 2009) | 1 line
#5190: export make_option in __all__.
........
r70869 | georg.brandl | 2009-03-31 14:14:42 -0500 (Tue, 31 Mar 2009) | 1 line
Fix-up unwanted change.
........
r70870 | georg.brandl | 2009-03-31 14:26:24 -0500 (Tue, 31 Mar 2009) | 1 line
#4411: document mro() and __mro__. (I hope I got it right.)
........
r70871 | georg.brandl | 2009-03-31 14:30:56 -0500 (Tue, 31 Mar 2009) | 1 line
#5618: fix typo.
........
r70872 | r.david.murray | 2009-03-31 14:31:17 -0500 (Tue, 31 Mar 2009) | 3 lines
Delete out-of-date and little-known README from the test
directory by consensus of devs at pycon sprint.
........
r70883 | georg.brandl | 2009-03-31 15:41:08 -0500 (Tue, 31 Mar 2009) | 1 line
#1674032: return value of flag from Event.wait(). OKed by Guido.
........
r70885 | tarek.ziade | 2009-03-31 15:48:31 -0500 (Tue, 31 Mar 2009) | 1 line
using log.warn for sys.stderr
........
r70893 | georg.brandl | 2009-03-31 15:56:32 -0500 (Tue, 31 Mar 2009) | 1 line
#1530012: move TQS section before raw strings.
........
r70894 | benjamin.peterson | 2009-03-31 16:06:30 -0500 (Tue, 31 Mar 2009) | 1 line
take the usual lock precautions around _active_limbo_lock
........
r70896 | georg.brandl | 2009-03-31 16:15:33 -0500 (Tue, 31 Mar 2009) | 1 line
#5598: document DocFileSuite *args argument.
........
r70897 | benjamin.peterson | 2009-03-31 16:34:42 -0500 (Tue, 31 Mar 2009) | 1 line
fix Thread.ident when it is the main thread or a dummy thread #5632
........
r70903 | georg.brandl | 2009-03-31 16:45:18 -0500 (Tue, 31 Mar 2009) | 1 line
#1676135: remove trailing slashes from --prefix argument.
........
r70905 | georg.brandl | 2009-03-31 17:03:40 -0500 (Tue, 31 Mar 2009) | 1 line
#5563: more documentation for bdist_msi.
........
r70906 | georg.brandl | 2009-03-31 17:11:53 -0500 (Tue, 31 Mar 2009) | 1 line
#1651995: fix _convert_ref for non-ASCII characters.
........
r70907 | georg.brandl | 2009-03-31 17:18:19 -0500 (Tue, 31 Mar 2009) | 1 line
#3427: document correct return type for urlopen().info().
........
r70915 | georg.brandl | 2009-03-31 17:40:16 -0500 (Tue, 31 Mar 2009) | 1 line
#5018: remove confusing paragraph.
........
r70927 | georg.brandl | 2009-03-31 18:01:27 -0500 (Tue, 31 Mar 2009) | 1 line
Dont shout to users.
........
r70933 | georg.brandl | 2009-03-31 19:04:33 -0500 (Tue, 31 Mar 2009) | 2 lines
Issue #5635: Fix running test_sys with tracing enabled.
........
r70951 | georg.brandl | 2009-04-01 09:02:27 -0500 (Wed, 01 Apr 2009) | 1 line
Add Maksim, who worked on several issues at the sprint.
........
r70960 | jesse.noller | 2009-04-01 11:42:19 -0500 (Wed, 01 Apr 2009) | 1 line
Issue 3270: document Listener address restrictions on windows
........
r70962 | brett.cannon | 2009-04-01 12:07:16 -0500 (Wed, 01 Apr 2009) | 2 lines
Ron DuPlain was given commit privileges at PyCon 2009 to work on 3to2.
........
r70963 | georg.brandl | 2009-04-01 12:46:01 -0500 (Wed, 01 Apr 2009) | 1 line
#5655: fix docstring oversight.
........
r70964 | brett.cannon | 2009-04-01 12:52:13 -0500 (Wed, 01 Apr 2009) | 2 lines
Paul Kippes was given commit privileges to work on 3to2.
........
r70998 | georg.brandl | 2009-04-01 16:54:21 -0500 (Wed, 01 Apr 2009) | 1 line
In Pdb, stop assigning values to __builtin__._ which interferes with the one commonly installed by gettext.
........
r71001 | brett.cannon | 2009-04-01 18:01:12 -0500 (Wed, 01 Apr 2009) | 3 lines
Add my initials to Misc/developers.txt. Names are now sorted by number of
characters in the person's name.
........
r71006 | georg.brandl | 2009-04-01 18:32:17 -0500 (Wed, 01 Apr 2009) | 1 line
Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
........
r71008 | andrew.kuchling | 2009-04-01 19:02:14 -0500 (Wed, 01 Apr 2009) | 1 line
Typo fix
........
r71010 | benjamin.peterson | 2009-04-01 19:11:52 -0500 (Wed, 01 Apr 2009) | 1 line
fix markup
........
r71011 | benjamin.peterson | 2009-04-01 19:12:47 -0500 (Wed, 01 Apr 2009) | 1 line
this should be :noindex:
........
r71019 | georg.brandl | 2009-04-01 21:00:01 -0500 (Wed, 01 Apr 2009) | 1 line
Fix test_doctest, missed two assignments to curframe.
........
r71037 | r.david.murray | 2009-04-01 23:34:04 -0500 (Wed, 01 Apr 2009) | 6 lines
Clarify that datetime strftime does not produce leap seconds and datetime
strptime does not accept it in the strftime behavior section of the
datetime docs.
Closes issue 2568.
........
r71056 | georg.brandl | 2009-04-02 12:43:07 -0500 (Thu, 02 Apr 2009) | 2 lines
Actually the displayhook should print the repr.
........
r71094 | vinay.sajip | 2009-04-03 05:23:18 -0500 (Fri, 03 Apr 2009) | 1 line
Added warning about logging use from asynchronous signal handlers.
........
r71101 | andrew.kuchling | 2009-04-03 16:43:00 -0500 (Fri, 03 Apr 2009) | 1 line
Add some items
........
r71102 | andrew.kuchling | 2009-04-03 16:44:49 -0500 (Fri, 03 Apr 2009) | 1 line
Fix 'the the'; grammar fix
........
r71103 | andrew.kuchling | 2009-04-03 16:45:29 -0500 (Fri, 03 Apr 2009) | 1 line
Fix 'the the' duplication
........
r71106 | vinay.sajip | 2009-04-03 16:58:16 -0500 (Fri, 03 Apr 2009) | 1 line
Clarified warning about logging use from asynchronous signal handlers.
........
r71119 | raymond.hettinger | 2009-04-04 00:37:47 -0500 (Sat, 04 Apr 2009) | 1 line
Add helpful link.
........
r71123 | r.david.murray | 2009-04-04 01:39:56 -0500 (Sat, 04 Apr 2009) | 2 lines
Fix error in description of 'oct' (issue 5678).
........
r71149 | georg.brandl | 2009-04-04 08:42:39 -0500 (Sat, 04 Apr 2009) | 1 line
#5642: clarify map() compatibility to the builtin.
........
r71150 | georg.brandl | 2009-04-04 08:45:49 -0500 (Sat, 04 Apr 2009) | 1 line
#5601: clarify that webbrowser is not meant for file names.
........
r71203 | benjamin.peterson | 2009-04-04 18:46:34 -0500 (Sat, 04 Apr 2009) | 1 line
note how using iter* are unsafe while mutating and document iter(dict)
........
r71212 | georg.brandl | 2009-04-05 05:24:20 -0500 (Sun, 05 Apr 2009) | 1 line
#1742837: expand HTTP server docs, and fix SocketServer ones to document methods as methods, not functions.
........
r71214 | georg.brandl | 2009-04-05 05:29:57 -0500 (Sun, 05 Apr 2009) | 1 line
Normalize spelling of Mac OS X.
........
r71215 | georg.brandl | 2009-04-05 05:32:26 -0500 (Sun, 05 Apr 2009) | 1 line
Avoid sure signs of a diseased mind.
........
r71216 | georg.brandl | 2009-04-05 05:41:02 -0500 (Sun, 05 Apr 2009) | 1 line
#1718017: document the relation of os.path and the posixpath, ntpath etc. modules better.
........
r71217 | georg.brandl | 2009-04-05 05:48:47 -0500 (Sun, 05 Apr 2009) | 1 line
#1726172: dont raise an unexpected IndexError if a voidresp() call has an empty response.
........
r71221 | vinay.sajip | 2009-04-05 06:06:24 -0500 (Sun, 05 Apr 2009) | 1 line
Issue #5695: Moved logging.captureWarnings() call inside with statement in WarningsTest.test_warnings.
........
r71240 | georg.brandl | 2009-04-05 09:40:06 -0500 (Sun, 05 Apr 2009) | 1 line
#5370: doc update about unpickling objects with custom __getattr__ etc. methods.
........
2009-04-05 16:13:16 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. describe:: len(s)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2016-02-08 13:58:40 -04:00
|
|
|
Return the number of elements in set *s* (cardinality of *s*).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. describe:: x in s
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Test *x* for membership in *s*.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. describe:: x not in s
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Test *x* for non-membership in *s*.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: isdisjoint(other)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2013-11-29 06:17:13 -04:00
|
|
|
Return ``True`` if the set has no elements in common with *other*. Sets are
|
2012-08-20 04:14:07 -03:00
|
|
|
disjoint if and only if their intersection is the empty set.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: issubset(other)
|
|
|
|
set <= other
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Test whether every element in the set is in *other*.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: set < other
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-11-01 16:47:54 -03:00
|
|
|
Test whether the set is a proper subset of *other*, that is,
|
2012-08-20 04:14:07 -03:00
|
|
|
``set <= other and set != other``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: issuperset(other)
|
|
|
|
set >= other
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Test whether every element in *other* is in the set.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: set > other
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-11-01 16:47:54 -03:00
|
|
|
Test whether the set is a proper superset of *other*, that is, ``set >=
|
2012-08-20 04:14:07 -03:00
|
|
|
other and set != other``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2016-09-13 03:38:50 -03:00
|
|
|
.. method:: union(*others)
|
2012-08-20 04:14:07 -03:00
|
|
|
set | other | ...
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Return a new set with elements from the set and all others.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2016-09-13 03:38:50 -03:00
|
|
|
.. method:: intersection(*others)
|
2012-08-20 04:14:07 -03:00
|
|
|
set & other & ...
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Return a new set with elements common to the set and all others.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2016-09-13 03:38:50 -03:00
|
|
|
.. method:: difference(*others)
|
2012-08-20 04:14:07 -03:00
|
|
|
set - other - ...
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Return a new set with elements in the set that are not in the others.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: symmetric_difference(other)
|
|
|
|
set ^ other
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Return a new set with elements in either the set or *other* but not both.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: copy()
|
2012-04-15 19:16:30 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Return a new set with a shallow copy of *s*.
|
2007-09-04 14:43:37 -03:00
|
|
|
|
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Note, the non-operator versions of :meth:`union`, :meth:`intersection`,
|
|
|
|
:meth:`difference`, and :meth:`symmetric_difference`, :meth:`issubset`, and
|
|
|
|
:meth:`issuperset` methods will accept any iterable as an argument. In
|
|
|
|
contrast, their operator based counterparts require their arguments to be
|
|
|
|
sets. This precludes error-prone constructions like ``set('abc') & 'cbs'``
|
|
|
|
in favor of the more readable ``set('abc').intersection('cbs')``.
|
2008-11-21 20:41:45 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Both :class:`set` and :class:`frozenset` support set to set comparisons. Two
|
|
|
|
sets are equal if and only if every element of each set is contained in the
|
|
|
|
other (each is a subset of the other). A set is less than another set if and
|
|
|
|
only if the first set is a proper subset of the second set (is a subset, but
|
|
|
|
is not equal). A set is greater than another set if and only if the first set
|
|
|
|
is a proper superset of the second set (is a superset, but is not equal).
|
2007-09-04 14:43:37 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Instances of :class:`set` are compared to instances of :class:`frozenset`
|
|
|
|
based on their members. For example, ``set('abc') == frozenset('abc')``
|
|
|
|
returns ``True`` and so does ``set('abc') in set([frozenset('abc')])``.
|
2007-09-04 14:43:37 -03:00
|
|
|
|
2013-05-06 22:22:43 -03:00
|
|
|
The subset and equality comparisons do not generalize to a total ordering
|
|
|
|
function. For example, any two nonempty disjoint sets are not equal and are not
|
2012-08-20 04:14:07 -03:00
|
|
|
subsets of each other, so *all* of the following return ``False``: ``a<b``,
|
|
|
|
``a==b``, or ``a>b``.
|
2007-09-04 14:43:37 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Since sets only define partial ordering (subset relationships), the output of
|
|
|
|
the :meth:`list.sort` method is undefined for lists of sets.
|
2007-09-04 14:43:37 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Set elements, like dictionary keys, must be :term:`hashable`.
|
2007-09-04 14:43:37 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Binary operations that mix :class:`set` instances with :class:`frozenset`
|
|
|
|
return the type of the first operand. For example: ``frozenset('ab') |
|
|
|
|
set('bc')`` returns an instance of :class:`frozenset`.
|
2007-09-04 14:43:37 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
The following table lists operations available for :class:`set` that do not
|
|
|
|
apply to immutable instances of :class:`frozenset`:
|
2007-09-04 14:43:37 -03:00
|
|
|
|
2016-09-13 03:38:50 -03:00
|
|
|
.. method:: update(*others)
|
2012-08-20 04:14:07 -03:00
|
|
|
set |= other | ...
|
2007-09-04 14:43:37 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Update the set, adding elements from all others.
|
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r70712 | benjamin.peterson | 2009-03-30 10:15:38 -0500 (Mon, 30 Mar 2009) | 1 line
don't rely on the order dict repr #5605
........
r70714 | brett.cannon | 2009-03-30 10:20:53 -0500 (Mon, 30 Mar 2009) | 1 line
Add an entry to developers.txt.
........
r70764 | martin.v.loewis | 2009-03-30 17:06:33 -0500 (Mon, 30 Mar 2009) | 2 lines
Add several VM developers.
........
r70765 | georg.brandl | 2009-03-30 17:09:34 -0500 (Mon, 30 Mar 2009) | 1 line
#5199: make warning about vars() assignment more visible.
........
r70769 | andrew.kuchling | 2009-03-30 17:29:53 -0500 (Mon, 30 Mar 2009) | 1 line
Remove comment
........
r70770 | andrew.kuchling | 2009-03-30 17:30:20 -0500 (Mon, 30 Mar 2009) | 1 line
Add several items and placeholders
........
r70771 | andrew.kuchling | 2009-03-30 17:31:11 -0500 (Mon, 30 Mar 2009) | 1 line
Many edits
........
r70773 | georg.brandl | 2009-03-30 17:43:00 -0500 (Mon, 30 Mar 2009) | 1 line
#5039: make it clear that the impl. note refers to CPython.
........
r70776 | andrew.kuchling | 2009-03-30 18:08:24 -0500 (Mon, 30 Mar 2009) | 1 line
typo fix
........
r70777 | andrew.kuchling | 2009-03-30 18:09:46 -0500 (Mon, 30 Mar 2009) | 1 line
Add more items
........
r70788 | andrew.kuchling | 2009-03-30 20:21:01 -0500 (Mon, 30 Mar 2009) | 1 line
Add various items
........
r70789 | georg.brandl | 2009-03-30 20:25:15 -0500 (Mon, 30 Mar 2009) | 1 line
Fix a wrong struct field assignment (docstring as closure).
........
r70824 | georg.brandl | 2009-03-31 10:43:20 -0500 (Tue, 31 Mar 2009) | 1 line
#5519: remove reference to Kodos, which seems dead.
........
r70828 | georg.brandl | 2009-03-31 10:50:16 -0500 (Tue, 31 Mar 2009) | 1 line
#5581: fget argument of abstractproperty is optional as well.
........
r70832 | georg.brandl | 2009-03-31 11:31:11 -0500 (Tue, 31 Mar 2009) | 1 line
#1386675: specify WindowsError as the exception, because it has a winerror attribute that EnvironmentError doesnt have.
........
r70836 | georg.brandl | 2009-03-31 11:50:25 -0500 (Tue, 31 Mar 2009) | 1 line
#5417: replace references to undocumented functions by ones to documented functions.
........
r70842 | georg.brandl | 2009-03-31 12:13:06 -0500 (Tue, 31 Mar 2009) | 1 line
#970783: document PyObject_Generic[GS]etAttr.
........
r70851 | georg.brandl | 2009-03-31 13:26:55 -0500 (Tue, 31 Mar 2009) | 1 line
#837577: note cryptic return value of spawn*e on invalid env dicts.
........
r70855 | georg.brandl | 2009-03-31 13:30:37 -0500 (Tue, 31 Mar 2009) | 1 line
#5245: note that PyRun_SimpleString doesnt return on SystemExit.
........
r70857 | georg.brandl | 2009-03-31 13:33:10 -0500 (Tue, 31 Mar 2009) | 1 line
#5227: note that Py_Main doesnt return on SystemExit.
........
r70866 | georg.brandl | 2009-03-31 14:06:57 -0500 (Tue, 31 Mar 2009) | 1 line
#4882: document named group behavior a bit better.
........
r70867 | georg.brandl | 2009-03-31 14:10:35 -0500 (Tue, 31 Mar 2009) | 1 line
#1096310: document usage of sys.__std*__ a bit better.
........
r70868 | georg.brandl | 2009-03-31 14:12:17 -0500 (Tue, 31 Mar 2009) | 1 line
#5190: export make_option in __all__.
........
r70869 | georg.brandl | 2009-03-31 14:14:42 -0500 (Tue, 31 Mar 2009) | 1 line
Fix-up unwanted change.
........
r70870 | georg.brandl | 2009-03-31 14:26:24 -0500 (Tue, 31 Mar 2009) | 1 line
#4411: document mro() and __mro__. (I hope I got it right.)
........
r70871 | georg.brandl | 2009-03-31 14:30:56 -0500 (Tue, 31 Mar 2009) | 1 line
#5618: fix typo.
........
r70872 | r.david.murray | 2009-03-31 14:31:17 -0500 (Tue, 31 Mar 2009) | 3 lines
Delete out-of-date and little-known README from the test
directory by consensus of devs at pycon sprint.
........
r70883 | georg.brandl | 2009-03-31 15:41:08 -0500 (Tue, 31 Mar 2009) | 1 line
#1674032: return value of flag from Event.wait(). OKed by Guido.
........
r70885 | tarek.ziade | 2009-03-31 15:48:31 -0500 (Tue, 31 Mar 2009) | 1 line
using log.warn for sys.stderr
........
r70893 | georg.brandl | 2009-03-31 15:56:32 -0500 (Tue, 31 Mar 2009) | 1 line
#1530012: move TQS section before raw strings.
........
r70894 | benjamin.peterson | 2009-03-31 16:06:30 -0500 (Tue, 31 Mar 2009) | 1 line
take the usual lock precautions around _active_limbo_lock
........
r70896 | georg.brandl | 2009-03-31 16:15:33 -0500 (Tue, 31 Mar 2009) | 1 line
#5598: document DocFileSuite *args argument.
........
r70897 | benjamin.peterson | 2009-03-31 16:34:42 -0500 (Tue, 31 Mar 2009) | 1 line
fix Thread.ident when it is the main thread or a dummy thread #5632
........
r70903 | georg.brandl | 2009-03-31 16:45:18 -0500 (Tue, 31 Mar 2009) | 1 line
#1676135: remove trailing slashes from --prefix argument.
........
r70905 | georg.brandl | 2009-03-31 17:03:40 -0500 (Tue, 31 Mar 2009) | 1 line
#5563: more documentation for bdist_msi.
........
r70906 | georg.brandl | 2009-03-31 17:11:53 -0500 (Tue, 31 Mar 2009) | 1 line
#1651995: fix _convert_ref for non-ASCII characters.
........
r70907 | georg.brandl | 2009-03-31 17:18:19 -0500 (Tue, 31 Mar 2009) | 1 line
#3427: document correct return type for urlopen().info().
........
r70915 | georg.brandl | 2009-03-31 17:40:16 -0500 (Tue, 31 Mar 2009) | 1 line
#5018: remove confusing paragraph.
........
r70927 | georg.brandl | 2009-03-31 18:01:27 -0500 (Tue, 31 Mar 2009) | 1 line
Dont shout to users.
........
r70933 | georg.brandl | 2009-03-31 19:04:33 -0500 (Tue, 31 Mar 2009) | 2 lines
Issue #5635: Fix running test_sys with tracing enabled.
........
r70951 | georg.brandl | 2009-04-01 09:02:27 -0500 (Wed, 01 Apr 2009) | 1 line
Add Maksim, who worked on several issues at the sprint.
........
r70960 | jesse.noller | 2009-04-01 11:42:19 -0500 (Wed, 01 Apr 2009) | 1 line
Issue 3270: document Listener address restrictions on windows
........
r70962 | brett.cannon | 2009-04-01 12:07:16 -0500 (Wed, 01 Apr 2009) | 2 lines
Ron DuPlain was given commit privileges at PyCon 2009 to work on 3to2.
........
r70963 | georg.brandl | 2009-04-01 12:46:01 -0500 (Wed, 01 Apr 2009) | 1 line
#5655: fix docstring oversight.
........
r70964 | brett.cannon | 2009-04-01 12:52:13 -0500 (Wed, 01 Apr 2009) | 2 lines
Paul Kippes was given commit privileges to work on 3to2.
........
r70998 | georg.brandl | 2009-04-01 16:54:21 -0500 (Wed, 01 Apr 2009) | 1 line
In Pdb, stop assigning values to __builtin__._ which interferes with the one commonly installed by gettext.
........
r71001 | brett.cannon | 2009-04-01 18:01:12 -0500 (Wed, 01 Apr 2009) | 3 lines
Add my initials to Misc/developers.txt. Names are now sorted by number of
characters in the person's name.
........
r71006 | georg.brandl | 2009-04-01 18:32:17 -0500 (Wed, 01 Apr 2009) | 1 line
Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
........
r71008 | andrew.kuchling | 2009-04-01 19:02:14 -0500 (Wed, 01 Apr 2009) | 1 line
Typo fix
........
r71010 | benjamin.peterson | 2009-04-01 19:11:52 -0500 (Wed, 01 Apr 2009) | 1 line
fix markup
........
r71011 | benjamin.peterson | 2009-04-01 19:12:47 -0500 (Wed, 01 Apr 2009) | 1 line
this should be :noindex:
........
r71019 | georg.brandl | 2009-04-01 21:00:01 -0500 (Wed, 01 Apr 2009) | 1 line
Fix test_doctest, missed two assignments to curframe.
........
r71037 | r.david.murray | 2009-04-01 23:34:04 -0500 (Wed, 01 Apr 2009) | 6 lines
Clarify that datetime strftime does not produce leap seconds and datetime
strptime does not accept it in the strftime behavior section of the
datetime docs.
Closes issue 2568.
........
r71056 | georg.brandl | 2009-04-02 12:43:07 -0500 (Thu, 02 Apr 2009) | 2 lines
Actually the displayhook should print the repr.
........
r71094 | vinay.sajip | 2009-04-03 05:23:18 -0500 (Fri, 03 Apr 2009) | 1 line
Added warning about logging use from asynchronous signal handlers.
........
r71101 | andrew.kuchling | 2009-04-03 16:43:00 -0500 (Fri, 03 Apr 2009) | 1 line
Add some items
........
r71102 | andrew.kuchling | 2009-04-03 16:44:49 -0500 (Fri, 03 Apr 2009) | 1 line
Fix 'the the'; grammar fix
........
r71103 | andrew.kuchling | 2009-04-03 16:45:29 -0500 (Fri, 03 Apr 2009) | 1 line
Fix 'the the' duplication
........
r71106 | vinay.sajip | 2009-04-03 16:58:16 -0500 (Fri, 03 Apr 2009) | 1 line
Clarified warning about logging use from asynchronous signal handlers.
........
r71119 | raymond.hettinger | 2009-04-04 00:37:47 -0500 (Sat, 04 Apr 2009) | 1 line
Add helpful link.
........
r71123 | r.david.murray | 2009-04-04 01:39:56 -0500 (Sat, 04 Apr 2009) | 2 lines
Fix error in description of 'oct' (issue 5678).
........
r71149 | georg.brandl | 2009-04-04 08:42:39 -0500 (Sat, 04 Apr 2009) | 1 line
#5642: clarify map() compatibility to the builtin.
........
r71150 | georg.brandl | 2009-04-04 08:45:49 -0500 (Sat, 04 Apr 2009) | 1 line
#5601: clarify that webbrowser is not meant for file names.
........
r71203 | benjamin.peterson | 2009-04-04 18:46:34 -0500 (Sat, 04 Apr 2009) | 1 line
note how using iter* are unsafe while mutating and document iter(dict)
........
r71212 | georg.brandl | 2009-04-05 05:24:20 -0500 (Sun, 05 Apr 2009) | 1 line
#1742837: expand HTTP server docs, and fix SocketServer ones to document methods as methods, not functions.
........
r71214 | georg.brandl | 2009-04-05 05:29:57 -0500 (Sun, 05 Apr 2009) | 1 line
Normalize spelling of Mac OS X.
........
r71215 | georg.brandl | 2009-04-05 05:32:26 -0500 (Sun, 05 Apr 2009) | 1 line
Avoid sure signs of a diseased mind.
........
r71216 | georg.brandl | 2009-04-05 05:41:02 -0500 (Sun, 05 Apr 2009) | 1 line
#1718017: document the relation of os.path and the posixpath, ntpath etc. modules better.
........
r71217 | georg.brandl | 2009-04-05 05:48:47 -0500 (Sun, 05 Apr 2009) | 1 line
#1726172: dont raise an unexpected IndexError if a voidresp() call has an empty response.
........
r71221 | vinay.sajip | 2009-04-05 06:06:24 -0500 (Sun, 05 Apr 2009) | 1 line
Issue #5695: Moved logging.captureWarnings() call inside with statement in WarningsTest.test_warnings.
........
r71240 | georg.brandl | 2009-04-05 09:40:06 -0500 (Sun, 05 Apr 2009) | 1 line
#5370: doc update about unpickling objects with custom __getattr__ etc. methods.
........
2009-04-05 16:13:16 -03:00
|
|
|
|
2016-09-13 03:38:50 -03:00
|
|
|
.. method:: intersection_update(*others)
|
2012-08-20 04:14:07 -03:00
|
|
|
set &= other & ...
|
2007-09-04 14:43:37 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Update the set, keeping only elements found in it and all others.
|
2007-09-04 14:43:37 -03:00
|
|
|
|
2016-09-13 03:38:50 -03:00
|
|
|
.. method:: difference_update(*others)
|
2012-08-20 04:14:07 -03:00
|
|
|
set -= other | ...
|
2007-09-04 14:43:37 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Update the set, removing elements found in others.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: symmetric_difference_update(other)
|
|
|
|
set ^= other
|
2007-09-04 14:58:02 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Update the set, keeping only elements found in either set, but not in both.
|
2007-09-04 14:58:02 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: add(elem)
|
2007-09-04 14:58:02 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Add element *elem* to the set.
|
2007-09-04 14:58:02 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: remove(elem)
|
2007-09-04 14:58:02 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Remove element *elem* from the set. Raises :exc:`KeyError` if *elem* is
|
|
|
|
not contained in the set.
|
2007-09-04 14:58:02 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: discard(elem)
|
2007-09-04 14:58:02 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Remove element *elem* from the set if it is present.
|
2008-09-09 19:15:27 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: pop()
|
2008-09-09 19:15:27 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Remove and return an arbitrary element from the set. Raises
|
|
|
|
:exc:`KeyError` if the set is empty.
|
2008-09-09 19:15:27 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: clear()
|
2008-09-09 19:15:27 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Remove all elements from the set.
|
2008-09-09 19:15:27 -03:00
|
|
|
|
2010-07-12 17:01:52 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Note, the non-operator versions of the :meth:`update`,
|
|
|
|
:meth:`intersection_update`, :meth:`difference_update`, and
|
|
|
|
:meth:`symmetric_difference_update` methods will accept any iterable as an
|
|
|
|
argument.
|
2008-09-10 18:47:03 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Note, the *elem* argument to the :meth:`__contains__`, :meth:`remove`, and
|
|
|
|
:meth:`discard` methods may be a set. To support searching for an equivalent
|
2017-06-01 11:12:01 -03:00
|
|
|
frozenset, a temporary one is created from *elem*.
|
2012-02-25 07:24:21 -04:00
|
|
|
|
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. _typesmapping:
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Mapping Types --- :class:`dict`
|
|
|
|
===============================
|
2008-09-09 19:15:27 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. index::
|
|
|
|
object: mapping
|
|
|
|
object: dictionary
|
|
|
|
triple: operations on; mapping; types
|
|
|
|
triple: operations on; dictionary; type
|
|
|
|
statement: del
|
|
|
|
builtin: len
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-11-03 16:05:55 -03:00
|
|
|
A :term:`mapping` object maps :term:`hashable` values to arbitrary objects.
|
2012-08-20 04:14:07 -03:00
|
|
|
Mappings are mutable objects. There is currently only one standard mapping
|
2012-08-21 04:42:52 -03:00
|
|
|
type, the :dfn:`dictionary`. (For other containers see the built-in
|
2012-08-20 04:14:07 -03:00
|
|
|
:class:`list`, :class:`set`, and :class:`tuple` classes, and the
|
|
|
|
:mod:`collections` module.)
|
2008-09-09 19:15:27 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
A dictionary's keys are *almost* arbitrary values. Values that are not
|
|
|
|
:term:`hashable`, that is, values containing lists, dictionaries or other
|
|
|
|
mutable types (that are compared by value rather than by object identity) may
|
|
|
|
not be used as keys. Numeric types used for keys obey the normal rules for
|
|
|
|
numeric comparison: if two numbers compare equal (such as ``1`` and ``1.0``)
|
|
|
|
then they can be used interchangeably to index the same dictionary entry. (Note
|
|
|
|
however, that since computers store floating-point numbers as approximations it
|
|
|
|
is usually unwise to use them as dictionary keys.)
|
2008-09-09 19:15:27 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Dictionaries can be created by placing a comma-separated list of ``key: value``
|
|
|
|
pairs within braces, for example: ``{'jack': 4098, 'sjoerd': 4127}`` or ``{4098:
|
|
|
|
'jack', 4127: 'sjoerd'}``, or by the :class:`dict` constructor.
|
2011-11-21 15:46:33 -04:00
|
|
|
|
2012-10-13 07:22:33 -03:00
|
|
|
.. class:: dict(**kwarg)
|
|
|
|
dict(mapping, **kwarg)
|
|
|
|
dict(iterable, **kwarg)
|
|
|
|
|
|
|
|
Return a new dictionary initialized from an optional positional argument
|
|
|
|
and a possibly empty set of keyword arguments.
|
|
|
|
|
|
|
|
If no positional argument is given, an empty dictionary is created.
|
|
|
|
If a positional argument is given and it is a mapping object, a dictionary
|
|
|
|
is created with the same key-value pairs as the mapping object. Otherwise,
|
2014-06-02 21:42:56 -03:00
|
|
|
the positional argument must be an :term:`iterable` object. Each item in
|
|
|
|
the iterable must itself be an iterable with exactly two objects. The
|
2012-10-13 07:22:33 -03:00
|
|
|
first object of each item becomes a key in the new dictionary, and the
|
|
|
|
second object the corresponding value. If a key occurs more than once, the
|
|
|
|
last value for that key becomes the corresponding value in the new
|
2012-08-20 04:14:07 -03:00
|
|
|
dictionary.
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-10-13 07:22:33 -03:00
|
|
|
If keyword arguments are given, the keyword arguments and their values are
|
|
|
|
added to the dictionary created from the positional argument. If a key
|
|
|
|
being added is already present, the value from the keyword argument
|
|
|
|
replaces the value from the positional argument.
|
2011-11-21 15:46:33 -04:00
|
|
|
|
2012-10-13 07:22:33 -03:00
|
|
|
To illustrate, the following examples all return a dictionary equal to
|
2012-10-26 13:14:16 -03:00
|
|
|
``{"one": 1, "two": 2, "three": 3}``::
|
2011-11-21 15:46:33 -04:00
|
|
|
|
2012-10-26 13:14:16 -03:00
|
|
|
>>> a = dict(one=1, two=2, three=3)
|
|
|
|
>>> b = {'one': 1, 'two': 2, 'three': 3}
|
|
|
|
>>> c = dict(zip(['one', 'two', 'three'], [1, 2, 3]))
|
|
|
|
>>> d = dict([('two', 2), ('one', 1), ('three', 3)])
|
|
|
|
>>> e = dict({'three': 3, 'one': 1, 'two': 2})
|
2012-10-13 07:22:33 -03:00
|
|
|
>>> a == b == c == d == e
|
|
|
|
True
|
|
|
|
|
|
|
|
Providing keyword arguments as in the first example only works for keys that
|
|
|
|
are valid Python identifiers. Otherwise, any valid keys can be used.
|
2011-11-21 15:46:33 -04:00
|
|
|
|
2010-09-09 09:59:39 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
These are the operations that dictionaries support (and therefore, custom
|
|
|
|
mapping types should support too):
|
2010-09-10 17:43:53 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. describe:: len(d)
|
2010-09-10 17:43:53 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Return the number of items in the dictionary *d*.
|
2010-09-10 17:43:53 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. describe:: d[key]
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Return the item of *d* with key *key*. Raises a :exc:`KeyError` if *key* is
|
|
|
|
not in the map.
|
2010-09-10 17:43:53 -03:00
|
|
|
|
2014-12-10 19:48:23 -04:00
|
|
|
.. index:: __missing__()
|
2014-12-10 19:49:58 -04:00
|
|
|
|
2014-12-10 19:38:19 -04:00
|
|
|
If a subclass of dict defines a method :meth:`__missing__` and *key*
|
2012-08-20 04:14:07 -03:00
|
|
|
is not present, the ``d[key]`` operation calls that method with the key *key*
|
|
|
|
as argument. The ``d[key]`` operation then returns or raises whatever is
|
2014-12-10 19:38:19 -04:00
|
|
|
returned or raised by the ``__missing__(key)`` call.
|
|
|
|
No other operations or methods invoke :meth:`__missing__`. If
|
2012-08-20 04:14:07 -03:00
|
|
|
:meth:`__missing__` is not defined, :exc:`KeyError` is raised.
|
|
|
|
:meth:`__missing__` must be a method; it cannot be an instance variable::
|
2010-09-10 17:43:53 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
>>> class Counter(dict):
|
|
|
|
... def __missing__(self, key):
|
|
|
|
... return 0
|
|
|
|
>>> c = Counter()
|
|
|
|
>>> c['red']
|
|
|
|
0
|
|
|
|
>>> c['red'] += 1
|
|
|
|
>>> c['red']
|
|
|
|
1
|
2010-09-10 17:43:53 -03:00
|
|
|
|
2014-12-10 19:38:19 -04:00
|
|
|
The example above shows part of the implementation of
|
|
|
|
:class:`collections.Counter`. A different ``__missing__`` method is used
|
|
|
|
by :class:`collections.defaultdict`.
|
2010-09-09 09:59:39 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. describe:: d[key] = value
|
2010-09-09 09:59:39 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Set ``d[key]`` to *value*.
|
2010-09-09 09:59:39 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. describe:: del d[key]
|
2010-09-09 09:59:39 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Remove ``d[key]`` from *d*. Raises a :exc:`KeyError` if *key* is not in the
|
|
|
|
map.
|
2010-09-09 09:59:39 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. describe:: key in d
|
2010-09-09 09:59:39 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Return ``True`` if *d* has a key *key*, else ``False``.
|
2008-09-09 19:15:27 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. describe:: key not in d
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Equivalent to ``not key in d``.
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. describe:: iter(d)
|
|
|
|
|
|
|
|
Return an iterator over the keys of the dictionary. This is a shortcut
|
|
|
|
for ``iter(d.keys())``.
|
|
|
|
|
|
|
|
.. method:: clear()
|
|
|
|
|
|
|
|
Remove all items from the dictionary.
|
|
|
|
|
|
|
|
.. method:: copy()
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Return a shallow copy of the dictionary.
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. classmethod:: fromkeys(seq[, value])
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Create a new dictionary with keys from *seq* and values set to *value*.
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
:meth:`fromkeys` is a class method that returns a new dictionary. *value*
|
|
|
|
defaults to ``None``.
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: get(key[, default])
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Return the value for *key* if *key* is in the dictionary, else *default*.
|
|
|
|
If *default* is not given, it defaults to ``None``, so that this method
|
|
|
|
never raises a :exc:`KeyError`.
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: items()
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Return a new view of the dictionary's items (``(key, value)`` pairs).
|
|
|
|
See the :ref:`documentation of view objects <dict-views>`.
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: keys()
|
2008-09-09 19:15:27 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Return a new view of the dictionary's keys. See the :ref:`documentation
|
|
|
|
of view objects <dict-views>`.
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: pop(key[, default])
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
If *key* is in the dictionary, remove it and return its value, else return
|
|
|
|
*default*. If *default* is not given and *key* is not in the dictionary,
|
|
|
|
a :exc:`KeyError` is raised.
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: popitem()
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Remove and return an arbitrary ``(key, value)`` pair from the dictionary.
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
:meth:`popitem` is useful to destructively iterate over a dictionary, as
|
|
|
|
often used in set algorithms. If the dictionary is empty, calling
|
|
|
|
:meth:`popitem` raises a :exc:`KeyError`.
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: setdefault(key[, default])
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
If *key* is in the dictionary, return its value. If not, insert *key*
|
|
|
|
with a value of *default* and return *default*. *default* defaults to
|
|
|
|
``None``.
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: update([other])
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Update the dictionary with the key/value pairs from *other*, overwriting
|
|
|
|
existing keys. Return ``None``.
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
:meth:`update` accepts either another dictionary object or an iterable of
|
|
|
|
key/value pairs (as tuples or other iterables of length two). If keyword
|
|
|
|
arguments are specified, the dictionary is then updated with those
|
|
|
|
key/value pairs: ``d.update(red=1, blue=2)``.
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. method:: values()
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Return a new view of the dictionary's values. See the
|
|
|
|
:ref:`documentation of view objects <dict-views>`.
|
2008-09-09 19:15:27 -03:00
|
|
|
|
2015-06-12 17:38:57 -03:00
|
|
|
Dictionaries compare equal if and only if they have the same ``(key,
|
|
|
|
value)`` pairs. Order comparisons ('<', '<=', '>=', '>') raise
|
|
|
|
:exc:`TypeError`.
|
2015-06-12 17:47:44 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. seealso::
|
|
|
|
:class:`types.MappingProxyType` can be used to create a read-only view
|
|
|
|
of a :class:`dict`.
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2008-09-09 19:15:27 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. _dict-views:
|
2008-09-09 19:15:27 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Dictionary view objects
|
|
|
|
-----------------------
|
2010-07-12 17:01:52 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
The objects returned by :meth:`dict.keys`, :meth:`dict.values` and
|
|
|
|
:meth:`dict.items` are *view objects*. They provide a dynamic view on the
|
|
|
|
dictionary's entries, which means that when the dictionary changes, the view
|
|
|
|
reflects these changes.
|
2008-09-09 19:15:27 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Dictionary views can be iterated over to yield their respective data, and
|
|
|
|
support membership tests:
|
2008-09-09 19:15:27 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. describe:: len(dictview)
|
2008-09-09 19:15:27 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Return the number of entries in the dictionary.
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. describe:: iter(dictview)
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Return an iterator over the keys, values or items (represented as tuples of
|
|
|
|
``(key, value)``) in the dictionary.
|
2008-09-09 19:15:27 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Keys and values are iterated over in an arbitrary order which is non-random,
|
|
|
|
varies across Python implementations, and depends on the dictionary's history
|
|
|
|
of insertions and deletions. If keys, values and items views are iterated
|
|
|
|
over with no intervening modifications to the dictionary, the order of items
|
|
|
|
will directly correspond. This allows the creation of ``(value, key)`` pairs
|
|
|
|
using :func:`zip`: ``pairs = zip(d.values(), d.keys())``. Another way to
|
|
|
|
create the same list is ``pairs = [(v, k) for (k, v) in d.items()]``.
|
2008-09-09 19:15:27 -03:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Iterating views while adding or deleting entries in the dictionary may raise
|
|
|
|
a :exc:`RuntimeError` or fail to iterate over all entries.
|
2010-12-28 07:08:17 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
.. describe:: x in dictview
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Return ``True`` if *x* is in the underlying dictionary's keys, values or
|
|
|
|
items (in the latter case, *x* should be a ``(key, value)`` tuple).
|
2012-02-25 07:24:21 -04:00
|
|
|
|
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
Keys views are set-like since their entries are unique and hashable. If all
|
|
|
|
values are hashable, so that ``(key, value)`` pairs are unique and hashable,
|
|
|
|
then the items view is also set-like. (Values views are not treated as set-like
|
|
|
|
since the entries are generally not unique.) For set-like views, all of the
|
|
|
|
operations defined for the abstract base class :class:`collections.abc.Set` are
|
|
|
|
available (for example, ``==``, ``<``, or ``^``).
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
An example of dictionary view usage::
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
>>> dishes = {'eggs': 2, 'sausage': 1, 'bacon': 1, 'spam': 500}
|
|
|
|
>>> keys = dishes.keys()
|
|
|
|
>>> values = dishes.values()
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
>>> # iteration
|
|
|
|
>>> n = 0
|
|
|
|
>>> for val in values:
|
|
|
|
... n += val
|
|
|
|
>>> print(n)
|
|
|
|
504
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
>>> # keys and values are iterated over in the same order
|
|
|
|
>>> list(keys)
|
|
|
|
['eggs', 'bacon', 'sausage', 'spam']
|
|
|
|
>>> list(values)
|
|
|
|
[2, 1, 1, 500]
|
2012-02-25 07:24:21 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
>>> # view objects are dynamic and reflect dict changes
|
|
|
|
>>> del dishes['eggs']
|
|
|
|
>>> del dishes['sausage']
|
|
|
|
>>> list(keys)
|
|
|
|
['spam', 'bacon']
|
2010-12-28 07:08:17 -04:00
|
|
|
|
2012-08-20 04:14:07 -03:00
|
|
|
>>> # set operations
|
|
|
|
>>> keys & {'eggs', 'bacon', 'salad'}
|
|
|
|
{'bacon'}
|
|
|
|
>>> keys ^ {'sausage', 'juice'}
|
|
|
|
{'juice', 'sausage', 'bacon', 'spam'}
|
2008-09-09 19:15:27 -03:00
|
|
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. _typecontextmanager:
|
|
|
|
|
|
|
|
Context Manager Types
|
|
|
|
=====================
|
|
|
|
|
|
|
|
.. index::
|
|
|
|
single: context manager
|
|
|
|
single: context management protocol
|
|
|
|
single: protocol; context management
|
|
|
|
|
|
|
|
Python's :keyword:`with` statement supports the concept of a runtime context
|
2010-12-12 16:09:18 -04:00
|
|
|
defined by a context manager. This is implemented using a pair of methods
|
2007-08-15 11:28:22 -03:00
|
|
|
that allow user-defined classes to define a runtime context that is entered
|
2010-12-12 16:09:18 -04:00
|
|
|
before the statement body is executed and exited when the statement ends:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. method:: contextmanager.__enter__()
|
|
|
|
|
|
|
|
Enter the runtime context and return either this object or another object
|
|
|
|
related to the runtime context. The value returned by this method is bound to
|
|
|
|
the identifier in the :keyword:`as` clause of :keyword:`with` statements using
|
|
|
|
this context manager.
|
|
|
|
|
2010-09-15 08:11:28 -03:00
|
|
|
An example of a context manager that returns itself is a :term:`file object`.
|
|
|
|
File objects return themselves from __enter__() to allow :func:`open` to be
|
|
|
|
used as the context expression in a :keyword:`with` statement.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
An example of a context manager that returns a related object is the one
|
Merged revisions 59703-59773 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59704 | christian.heimes | 2008-01-04 04:15:05 +0100 (Fri, 04 Jan 2008) | 1 line
Moved include "Python.h" in front of other imports to silence a warning.
........
r59706 | raymond.hettinger | 2008-01-04 04:22:53 +0100 (Fri, 04 Jan 2008) | 10 lines
Minor fix-ups to named tuples:
* Make the _replace() method respect subclassing.
* Using property() to make _fields read-only wasn't a good idea.
It caused len(Point._fields) to fail.
* Add note to _cast() about length checking and alternative with the star-operator.
........
r59707 | jeffrey.yasskin | 2008-01-04 09:01:23 +0100 (Fri, 04 Jan 2008) | 3 lines
Make math.{floor,ceil}({int,long}) return float again for backwards
compatibility after r59671 made them return integral types.
........
r59709 | christian.heimes | 2008-01-04 14:21:07 +0100 (Fri, 04 Jan 2008) | 1 line
Bug #1713: posixpath.ismount() claims symlink to a mountpoint is a mountpoint.
........
r59712 | lars.gustaebel | 2008-01-04 15:00:33 +0100 (Fri, 04 Jan 2008) | 5 lines
Issue #1735: TarFile.extractall() now correctly sets
directory permissions and times.
(will backport to 2.5)
........
r59714 | andrew.kuchling | 2008-01-04 15:47:17 +0100 (Fri, 04 Jan 2008) | 1 line
Update links to bug/patch tracker
........
r59716 | christian.heimes | 2008-01-04 16:23:30 +0100 (Fri, 04 Jan 2008) | 1 line
Added interface to Windows' WSAIoctl and a simple example for a network sniffer.
........
r59717 | christian.heimes | 2008-01-04 16:29:00 +0100 (Fri, 04 Jan 2008) | 1 line
And here is the rest of Hirokazu Yamamoto's patch for VS6.0 support. Thanks Hiro!
........
r59719 | christian.heimes | 2008-01-04 16:34:06 +0100 (Fri, 04 Jan 2008) | 1 line
Reverted last transaction. It's the wrong branch.
........
r59721 | christian.heimes | 2008-01-04 16:48:06 +0100 (Fri, 04 Jan 2008) | 1 line
socket.ioctl is only available on Windows
........
r59722 | andrew.kuchling | 2008-01-04 19:24:41 +0100 (Fri, 04 Jan 2008) | 1 line
Fix markup
........
r59723 | andrew.kuchling | 2008-01-04 19:25:05 +0100 (Fri, 04 Jan 2008) | 1 line
Fix markup
........
r59725 | guido.van.rossum | 2008-01-05 01:59:59 +0100 (Sat, 05 Jan 2008) | 3 lines
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
and adds errors for -0x.
........
r59726 | guido.van.rossum | 2008-01-05 02:21:57 +0100 (Sat, 05 Jan 2008) | 2 lines
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
........
r59727 | raymond.hettinger | 2008-01-05 02:35:43 +0100 (Sat, 05 Jan 2008) | 1 line
Improve namedtuple's _cast() method with a docstring, new name, and error-checking.
........
r59728 | raymond.hettinger | 2008-01-05 03:17:24 +0100 (Sat, 05 Jan 2008) | 1 line
Add error-checking to namedtuple's _replace() method.
........
r59730 | fred.drake | 2008-01-05 05:38:38 +0100 (Sat, 05 Jan 2008) | 2 lines
clean up a comment
........
r59731 | jeffrey.yasskin | 2008-01-05 09:47:13 +0100 (Sat, 05 Jan 2008) | 11 lines
Continue rolling back pep-3141 changes that changed behavior from 2.5. This
round included:
* Revert round to its 2.6 behavior (half away from 0).
* Because round, floor, and ceil always return float again, it's no
longer necessary to have them delegate to __xxx___, so I've ripped
that out of their implementations and the Real ABC. This also helps
in implementing types that work in both 2.6 and 3.0: you return int
from the __xxx__ methods, and let it get enabled by the version
upgrade.
* Make pow(-1, .5) raise a ValueError again.
........
r59736 | andrew.kuchling | 2008-01-05 16:13:49 +0100 (Sat, 05 Jan 2008) | 1 line
Fix comment typo
........
r59738 | thomas.heller | 2008-01-05 18:15:44 +0100 (Sat, 05 Jan 2008) | 1 line
Add myself.
........
r59739 | georg.brandl | 2008-01-05 18:49:17 +0100 (Sat, 05 Jan 2008) | 2 lines
Fix C++-style comment.
........
r59742 | georg.brandl | 2008-01-05 20:28:16 +0100 (Sat, 05 Jan 2008) | 2 lines
Remove with_statement future imports from 2.6 docs.
........
r59743 | georg.brandl | 2008-01-05 20:29:45 +0100 (Sat, 05 Jan 2008) | 2 lines
Simplify index entries; fix #1712.
........
r59744 | georg.brandl | 2008-01-05 20:44:22 +0100 (Sat, 05 Jan 2008) | 2 lines
Doc patch #1730 from Robin Stocker; minor corrections mostly to os.rst.
........
r59749 | georg.brandl | 2008-01-05 21:29:13 +0100 (Sat, 05 Jan 2008) | 2 lines
Revert socket.rst to unix-eol.
........
r59750 | georg.brandl | 2008-01-05 21:33:46 +0100 (Sat, 05 Jan 2008) | 2 lines
Set native svn:eol-style property for text files.
........
r59752 | georg.brandl | 2008-01-05 21:46:29 +0100 (Sat, 05 Jan 2008) | 2 lines
#1719: capitalization error in "UuidCreate".
........
r59753 | georg.brandl | 2008-01-05 22:02:25 +0100 (Sat, 05 Jan 2008) | 2 lines
Repair markup.
........
r59754 | georg.brandl | 2008-01-05 22:10:50 +0100 (Sat, 05 Jan 2008) | 2 lines
Use markup.
........
r59757 | christian.heimes | 2008-01-05 22:35:52 +0100 (Sat, 05 Jan 2008) | 1 line
Final adjustments for #1601
........
r59758 | guido.van.rossum | 2008-01-05 23:19:06 +0100 (Sat, 05 Jan 2008) | 3 lines
Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
Fix by John Nagle.
........
r59759 | guido.van.rossum | 2008-01-05 23:20:01 +0100 (Sat, 05 Jan 2008) | 2 lines
Add John Nagle (of issue #1637).
........
r59765 | raymond.hettinger | 2008-01-06 10:02:24 +0100 (Sun, 06 Jan 2008) | 1 line
Small code simplification. Forgot that classmethods can be called from intances.
........
r59766 | martin.v.loewis | 2008-01-06 11:09:48 +0100 (Sun, 06 Jan 2008) | 2 lines
Use vcbuild for VS 2009.
........
r59767 | martin.v.loewis | 2008-01-06 12:03:43 +0100 (Sun, 06 Jan 2008) | 2 lines
Package using VS 2008.
........
r59768 | martin.v.loewis | 2008-01-06 12:13:16 +0100 (Sun, 06 Jan 2008) | 2 lines
Don't try to package msvcr90 for the moment.
........
r59769 | georg.brandl | 2008-01-06 15:17:36 +0100 (Sun, 06 Jan 2008) | 4 lines
#1696393: don't check for '.' and '..' in ntpath.walk since
they aren't returned from os.listdir anymore.
Reported by Michael Haggerty.
........
r59770 | georg.brandl | 2008-01-06 15:27:15 +0100 (Sun, 06 Jan 2008) | 3 lines
#1742: don't raise exception on os.path.relpath("a", "a"), but return os.curdir.
Reported by Jesse Towner.
........
r59771 | georg.brandl | 2008-01-06 15:33:52 +0100 (Sun, 06 Jan 2008) | 2 lines
#1591: Clarify docstring of Popen3.
........
r59772 | georg.brandl | 2008-01-06 16:30:34 +0100 (Sun, 06 Jan 2008) | 2 lines
#1680: fix context manager example function name.
........
r59773 | georg.brandl | 2008-01-06 16:34:57 +0100 (Sun, 06 Jan 2008) | 2 lines
#1755097: document default values for [].sort() and sorted().
........
2008-01-06 12:59:19 -04:00
|
|
|
returned by :func:`decimal.localcontext`. These managers set the active
|
2007-08-15 11:28:22 -03:00
|
|
|
decimal context to a copy of the original decimal context and then return the
|
|
|
|
copy. This allows changes to be made to the current decimal context in the body
|
|
|
|
of the :keyword:`with` statement without affecting code outside the
|
|
|
|
:keyword:`with` statement.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: contextmanager.__exit__(exc_type, exc_val, exc_tb)
|
|
|
|
|
#1370: Finish the merge r58749, log below, by resolving all conflicts in Doc/.
Merged revisions 58221-58741 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58221 | georg.brandl | 2007-09-20 10:57:59 -0700 (Thu, 20 Sep 2007) | 2 lines
Patch #1181: add os.environ.clear() method.
........
r58225 | sean.reifschneider | 2007-09-20 23:33:28 -0700 (Thu, 20 Sep 2007) | 3 lines
Issue1704287: "make install" fails unless you do "make" first. Make
oldsharedmods and sharedmods in "libinstall".
........
r58232 | guido.van.rossum | 2007-09-22 13:18:03 -0700 (Sat, 22 Sep 2007) | 4 lines
Patch # 188 by Philip Jenvey.
Make tell() mark CRLF as a newline.
With unit test.
........
r58242 | georg.brandl | 2007-09-24 10:55:47 -0700 (Mon, 24 Sep 2007) | 2 lines
Fix typo and double word.
........
r58245 | georg.brandl | 2007-09-24 10:59:28 -0700 (Mon, 24 Sep 2007) | 2 lines
#1196: document default radix for int().
........
r58247 | georg.brandl | 2007-09-24 11:08:24 -0700 (Mon, 24 Sep 2007) | 2 lines
#1177: accept 2xx responses for https too, not only http.
........
r58249 | andrew.kuchling | 2007-09-24 16:45:51 -0700 (Mon, 24 Sep 2007) | 1 line
Remove stray odd character; grammar fix
........
r58250 | andrew.kuchling | 2007-09-24 16:46:28 -0700 (Mon, 24 Sep 2007) | 1 line
Typo fix
........
r58251 | andrew.kuchling | 2007-09-24 17:09:42 -0700 (Mon, 24 Sep 2007) | 1 line
Add various items
........
r58268 | vinay.sajip | 2007-09-26 22:34:45 -0700 (Wed, 26 Sep 2007) | 1 line
Change to flush and close logic to fix #1760556.
........
r58269 | vinay.sajip | 2007-09-26 22:38:51 -0700 (Wed, 26 Sep 2007) | 1 line
Change to basicConfig() to fix #1021.
........
r58270 | georg.brandl | 2007-09-26 23:26:58 -0700 (Wed, 26 Sep 2007) | 2 lines
#1208: document match object's boolean value.
........
r58271 | vinay.sajip | 2007-09-26 23:56:13 -0700 (Wed, 26 Sep 2007) | 1 line
Minor date change.
........
r58272 | vinay.sajip | 2007-09-27 00:35:10 -0700 (Thu, 27 Sep 2007) | 1 line
Change to LogRecord.__init__() to fix #1206. Note that archaic use of type(x) == types.DictType is because of keeping 1.5.2 compatibility. While this is much less relevant these days, there probably needs to be a separate commit for removing all archaic constructs at the same time.
........
r58288 | brett.cannon | 2007-09-30 12:45:10 -0700 (Sun, 30 Sep 2007) | 9 lines
tuple.__repr__ did not consider a reference loop as it is not possible from
Python code; but it is possible from C. object.__str__ had the issue of not
expecting a type to doing something within it's tp_str implementation that
could trigger an infinite recursion, but it could in C code.. Both found
thanks to BaseException and how it handles its repr.
Closes issue #1686386. Thanks to Thomas Herve for taking an initial stab at
coming up with a solution.
........
r58289 | brett.cannon | 2007-09-30 13:37:19 -0700 (Sun, 30 Sep 2007) | 3 lines
Fix error introduced by r58288; if a tuple is length 0 return its repr and
don't worry about any self-referring tuples.
........
r58294 | facundo.batista | 2007-10-02 10:01:24 -0700 (Tue, 02 Oct 2007) | 11 lines
Made the various is_* operations return booleans. This was discussed
with Cawlishaw by mail, and he basically confirmed that to these is_*
operations, there's no need to return Decimal(0) and Decimal(1) if
the language supports the False and True booleans.
Also added a few tests for the these functions in extra.decTest, since
they are mostly untested (apart from the doctests).
Thanks Mark Dickinson
........
r58295 | facundo.batista | 2007-10-02 11:21:18 -0700 (Tue, 02 Oct 2007) | 4 lines
Added a class to store the digits of log(10), so that they can be made
available when necessary without recomputing. Thanks Mark Dickinson
........
r58299 | mark.summerfield | 2007-10-03 01:53:21 -0700 (Wed, 03 Oct 2007) | 4 lines
Added note in footnote about string comparisons about
unicodedata.normalize().
........
r58304 | raymond.hettinger | 2007-10-03 14:18:11 -0700 (Wed, 03 Oct 2007) | 1 line
enumerate() is no longer bounded to using sequences shorter than LONG_MAX. The possibility of overflow was sending some newsgroup posters into a tizzy.
........
r58305 | raymond.hettinger | 2007-10-03 17:20:27 -0700 (Wed, 03 Oct 2007) | 1 line
itertools.count() no longer limited to sys.maxint.
........
r58306 | kurt.kaiser | 2007-10-03 18:49:54 -0700 (Wed, 03 Oct 2007) | 3 lines
Assume that the user knows when he wants to end the line; don't insert
something he didn't select or complete.
........
r58307 | kurt.kaiser | 2007-10-03 19:07:50 -0700 (Wed, 03 Oct 2007) | 2 lines
Remove unused theme that was causing a fault in p3k.
........
r58308 | kurt.kaiser | 2007-10-03 19:09:17 -0700 (Wed, 03 Oct 2007) | 2 lines
Clean up EditorWindow close.
........
r58309 | kurt.kaiser | 2007-10-03 19:53:07 -0700 (Wed, 03 Oct 2007) | 7 lines
textView cleanup. Patch 1718043 Tal Einat.
M idlelib/EditorWindow.py
M idlelib/aboutDialog.py
M idlelib/textView.py
M idlelib/NEWS.txt
........
r58310 | kurt.kaiser | 2007-10-03 20:11:12 -0700 (Wed, 03 Oct 2007) | 3 lines
configDialog cleanup. Patch 1730217 Tal Einat.
........
r58311 | neal.norwitz | 2007-10-03 23:00:48 -0700 (Wed, 03 Oct 2007) | 4 lines
Coverity #151: Remove deadcode.
All this code already exists above starting at line 653.
........
r58325 | fred.drake | 2007-10-04 19:46:12 -0700 (Thu, 04 Oct 2007) | 1 line
wrap lines to <80 characters before fixing errors
........
r58326 | raymond.hettinger | 2007-10-04 19:47:07 -0700 (Thu, 04 Oct 2007) | 6 lines
Add __asdict__() to NamedTuple and refine the docs.
Add maxlen support to deque() and fixup docs.
Partially fix __reduce__(). The None as a third arg was no longer supported.
Still needs work on __reduce__() to handle recursive inputs.
........
r58327 | fred.drake | 2007-10-04 19:48:32 -0700 (Thu, 04 Oct 2007) | 3 lines
move descriptions of ac_(in|out)_buffer_size to the right place
http://bugs.python.org/issue1053
........
r58329 | neal.norwitz | 2007-10-04 20:39:17 -0700 (Thu, 04 Oct 2007) | 3 lines
dict could be NULL, so we need to XDECREF.
Fix a compiler warning about passing a PyTypeObject* instead of PyObject*.
........
r58330 | neal.norwitz | 2007-10-04 20:41:19 -0700 (Thu, 04 Oct 2007) | 2 lines
Fix Coverity #158: Check the correct variable.
........
r58332 | neal.norwitz | 2007-10-04 22:01:38 -0700 (Thu, 04 Oct 2007) | 7 lines
Fix Coverity #159.
This code was broken if save() returned a negative number since i contained
a boolean value and then we compared i < 0 which should never be true.
Will backport (assuming it's necessary)
........
r58334 | neal.norwitz | 2007-10-04 22:29:17 -0700 (Thu, 04 Oct 2007) | 1 line
Add a note about fixing some more warnings found by Coverity.
........
r58338 | raymond.hettinger | 2007-10-05 12:07:31 -0700 (Fri, 05 Oct 2007) | 1 line
Restore BEGIN/END THREADS macros which were squashed in the previous checkin
........
r58343 | gregory.p.smith | 2007-10-06 00:48:10 -0700 (Sat, 06 Oct 2007) | 3 lines
Stab in the dark attempt to fix the test_bsddb3 failure on sparc and S-390
ubuntu buildbots.
........
r58344 | gregory.p.smith | 2007-10-06 00:51:59 -0700 (Sat, 06 Oct 2007) | 2 lines
Allows BerkeleyDB 4.6.x >= 4.6.21 for the bsddb module.
........
r58348 | gregory.p.smith | 2007-10-06 08:47:37 -0700 (Sat, 06 Oct 2007) | 3 lines
Use the host the author likely meant in the first place. pop.gmail.com is
reliable. gmail.org is someones personal domain.
........
r58351 | neal.norwitz | 2007-10-06 12:16:28 -0700 (Sat, 06 Oct 2007) | 3 lines
Ensure that this test will pass even if another test left an unwritable TESTFN.
Also use the safe unlink in test_support instead of rolling our own here.
........
r58368 | georg.brandl | 2007-10-08 00:50:24 -0700 (Mon, 08 Oct 2007) | 3 lines
#1123: fix the docs for the str.split(None, sep) case.
Also expand a few other methods' docs, which had more info in the deprecated string module docs.
........
r58369 | georg.brandl | 2007-10-08 01:06:05 -0700 (Mon, 08 Oct 2007) | 2 lines
Update docstring of sched, also remove an unused assignment.
........
r58370 | raymond.hettinger | 2007-10-08 02:14:28 -0700 (Mon, 08 Oct 2007) | 5 lines
Add comments to NamedTuple code.
Let the field spec be either a string or a non-string sequence (suggested by Martin Blais with use cases).
Improve the error message in the case of a SyntaxError (caused by a duplicate field name).
........
r58371 | raymond.hettinger | 2007-10-08 02:56:29 -0700 (Mon, 08 Oct 2007) | 1 line
Missed a line in the docs
........
r58372 | raymond.hettinger | 2007-10-08 03:11:51 -0700 (Mon, 08 Oct 2007) | 1 line
Better variable names
........
r58376 | georg.brandl | 2007-10-08 07:12:47 -0700 (Mon, 08 Oct 2007) | 3 lines
#1199: docs for tp_as_{number,sequence,mapping}, by Amaury Forgeot d'Arc.
No need to merge this to py3k!
........
r58380 | raymond.hettinger | 2007-10-08 14:26:58 -0700 (Mon, 08 Oct 2007) | 1 line
Eliminate camelcase function name
........
r58381 | andrew.kuchling | 2007-10-08 16:23:03 -0700 (Mon, 08 Oct 2007) | 1 line
Eliminate camelcase function name
........
r58382 | raymond.hettinger | 2007-10-08 18:36:23 -0700 (Mon, 08 Oct 2007) | 1 line
Make the error messages more specific
........
r58384 | gregory.p.smith | 2007-10-08 23:02:21 -0700 (Mon, 08 Oct 2007) | 10 lines
Splits Modules/_bsddb.c up into bsddb.h and _bsddb.c and adds a C API
object available as bsddb.db.api. This is based on the patch submitted
by Duncan Grisby here:
http://sourceforge.net/tracker/index.php?func=detail&aid=1551895&group_id=13900&atid=313900
See this thread for additional info:
http://sourceforge.net/mailarchive/forum.php?thread_name=E1GAVDK-0002rk-Iw%40apasphere.com&forum_name=pybsddb-users
It also cleans up the code a little by removing some ifdef/endifs for
python prior to 2.1 and for unsupported Berkeley DB <= 3.2.
........
r58385 | gregory.p.smith | 2007-10-08 23:50:43 -0700 (Mon, 08 Oct 2007) | 5 lines
Fix a double free when positioning a database cursor to a non-existant
string key (and probably a few other situations with string keys).
This was reported with a patch as pybsddb sourceforge bug 1708868 by
jjjhhhlll at gmail.
........
r58386 | gregory.p.smith | 2007-10-09 00:19:11 -0700 (Tue, 09 Oct 2007) | 3 lines
Use the highest cPickle protocol in bsddb.dbshelve. This comes from
sourceforge pybsddb patch 1551443 by w_barnes.
........
r58394 | gregory.p.smith | 2007-10-09 11:26:02 -0700 (Tue, 09 Oct 2007) | 2 lines
remove another sleepycat reference
........
r58396 | kurt.kaiser | 2007-10-09 12:31:30 -0700 (Tue, 09 Oct 2007) | 3 lines
Allow interrupt only when executing user code in subprocess
Patch 1225 Tal Einat modified from IDLE-Spoon.
........
r58399 | brett.cannon | 2007-10-09 17:07:50 -0700 (Tue, 09 Oct 2007) | 5 lines
Remove file-level typedefs that were inconsistently used throughout the file.
Just move over to the public API names.
Closes issue1238.
........
r58401 | raymond.hettinger | 2007-10-09 17:26:46 -0700 (Tue, 09 Oct 2007) | 1 line
Accept Jim Jewett's api suggestion to use None instead of -1 to indicate unbounded deques.
........
r58403 | kurt.kaiser | 2007-10-09 17:55:40 -0700 (Tue, 09 Oct 2007) | 2 lines
Allow cursor color change w/o restart. Patch 1725576 Tal Einat.
........
r58404 | kurt.kaiser | 2007-10-09 18:06:47 -0700 (Tue, 09 Oct 2007) | 2 lines
show paste if > 80 columns. Patch 1659326 Tal Einat.
........
r58415 | thomas.heller | 2007-10-11 12:51:32 -0700 (Thu, 11 Oct 2007) | 5 lines
On OS X, use os.uname() instead of gestalt.sysv(...) to get the
operating system version. This allows to use ctypes when Python
was configured with --disable-toolbox-glue.
........
r58419 | neal.norwitz | 2007-10-11 20:01:01 -0700 (Thu, 11 Oct 2007) | 1 line
Get rid of warning about not being able to create an existing directory.
........
r58420 | neal.norwitz | 2007-10-11 20:01:30 -0700 (Thu, 11 Oct 2007) | 1 line
Get rid of warnings on a bunch of platforms by using a proper prototype.
........
r58421 | neal.norwitz | 2007-10-11 20:01:54 -0700 (Thu, 11 Oct 2007) | 4 lines
Get rid of compiler warning about retval being used (returned) without
being initialized. (gcc warning and Coverity 202)
........
r58422 | neal.norwitz | 2007-10-11 20:03:23 -0700 (Thu, 11 Oct 2007) | 1 line
Fix Coverity 168: Close the file before returning (exiting).
........
r58423 | neal.norwitz | 2007-10-11 20:04:18 -0700 (Thu, 11 Oct 2007) | 4 lines
Fix Coverity 180: Don't overallocate. We don't need structs, but pointers.
Also fix a memory leak.
........
r58424 | neal.norwitz | 2007-10-11 20:05:19 -0700 (Thu, 11 Oct 2007) | 5 lines
Fix Coverity 185-186: If the passed in FILE is NULL, uninitialized memory
would be accessed.
Will backport.
........
r58425 | neal.norwitz | 2007-10-11 20:52:34 -0700 (Thu, 11 Oct 2007) | 1 line
Get this module to compile with bsddb versions prior to 4.3
........
r58430 | martin.v.loewis | 2007-10-12 01:56:52 -0700 (Fri, 12 Oct 2007) | 3 lines
Bug #1216: Restore support for Visual Studio 2002.
Will backport to 2.5.
........
r58433 | raymond.hettinger | 2007-10-12 10:53:11 -0700 (Fri, 12 Oct 2007) | 1 line
Fix test of count.__repr__() to ignore the 'L' if the count is a long
........
r58434 | gregory.p.smith | 2007-10-12 11:44:06 -0700 (Fri, 12 Oct 2007) | 4 lines
Fixes http://bugs.python.org/issue1233 - bsddb.dbshelve.DBShelf.append
was useless due to inverted logic. Also adds a test case for RECNO dbs
to test_dbshelve.
........
r58445 | georg.brandl | 2007-10-13 06:20:03 -0700 (Sat, 13 Oct 2007) | 2 lines
Fix email example.
........
r58450 | gregory.p.smith | 2007-10-13 16:02:05 -0700 (Sat, 13 Oct 2007) | 2 lines
Fix an uncollectable reference leak in bsddb.db.DBShelf.append
........
r58453 | neal.norwitz | 2007-10-13 17:18:40 -0700 (Sat, 13 Oct 2007) | 8 lines
Let the O/S supply a port if none of the default ports can be used.
This should make the tests more robust at the expense of allowing
tests to be sloppier by not requiring them to cleanup after themselves.
(It will legitamitely help when running two test suites simultaneously
or if another process is already using one of the predefined ports.)
Also simplifies (slightLy) the exception handling elsewhere.
........
r58459 | neal.norwitz | 2007-10-14 11:30:21 -0700 (Sun, 14 Oct 2007) | 2 lines
Don't raise a string exception, they don't work anymore.
........
r58460 | neal.norwitz | 2007-10-14 11:40:37 -0700 (Sun, 14 Oct 2007) | 1 line
Use unittest for assertions
........
r58468 | armin.rigo | 2007-10-15 00:48:35 -0700 (Mon, 15 Oct 2007) | 2 lines
test_bigbits was not testing what it seemed to.
........
r58471 | guido.van.rossum | 2007-10-15 08:54:11 -0700 (Mon, 15 Oct 2007) | 3 lines
Change a PyErr_Print() into a PyErr_Clear(),
per discussion in issue 1031213.
........
r58500 | raymond.hettinger | 2007-10-16 12:18:30 -0700 (Tue, 16 Oct 2007) | 1 line
Improve error messages
........
r58506 | raymond.hettinger | 2007-10-16 14:28:32 -0700 (Tue, 16 Oct 2007) | 1 line
More docs, error messages, and tests
........
r58507 | andrew.kuchling | 2007-10-16 15:58:03 -0700 (Tue, 16 Oct 2007) | 1 line
Add items
........
r58508 | brett.cannon | 2007-10-16 16:24:06 -0700 (Tue, 16 Oct 2007) | 3 lines
Remove ``:const:`` notation on None in parameter list. Since the markup is not
rendered for parameters it just showed up as ``:const:`None` `` in the output.
........
r58509 | brett.cannon | 2007-10-16 16:26:45 -0700 (Tue, 16 Oct 2007) | 3 lines
Re-order some functions whose parameters differ between PyObject and const char
* so that they are next to each other.
........
r58522 | armin.rigo | 2007-10-17 11:46:37 -0700 (Wed, 17 Oct 2007) | 5 lines
Fix the overflow checking of list_repeat.
Introduce overflow checking into list_inplace_repeat.
Backport candidate, possibly.
........
r58530 | facundo.batista | 2007-10-17 20:16:03 -0700 (Wed, 17 Oct 2007) | 7 lines
Issue #1580738. When HTTPConnection reads the whole stream with read(),
it closes itself. When the stream is read in several calls to read(n),
it should behave in the same way if HTTPConnection knows where the end
of the stream is (through self.length). Added a test case for this
behaviour.
........
r58531 | facundo.batista | 2007-10-17 20:44:48 -0700 (Wed, 17 Oct 2007) | 3 lines
Issue 1289, just a typo.
........
r58532 | gregory.p.smith | 2007-10-18 00:56:54 -0700 (Thu, 18 Oct 2007) | 4 lines
cleanup test_dbtables to use mkdtemp. cleanup dbtables to pass txn as a
keyword argument whenever possible to avoid bugs and confusion. (dbtables.py
line 447 self.db.get using txn as a non-keyword was an actual bug due to this)
........
r58533 | gregory.p.smith | 2007-10-18 01:34:20 -0700 (Thu, 18 Oct 2007) | 4 lines
Fix a weird bug in dbtables: if it chose a random rowid string that contained
NULL bytes it would cause the database all sorts of problems in the future
leading to very strange random failures and corrupt dbtables.bsdTableDb dbs.
........
r58534 | gregory.p.smith | 2007-10-18 09:32:02 -0700 (Thu, 18 Oct 2007) | 3 lines
A cleaner fix than the one committed last night. Generate random rowids that
do not contain null bytes.
........
r58537 | gregory.p.smith | 2007-10-18 10:17:57 -0700 (Thu, 18 Oct 2007) | 2 lines
mention bsddb fixes.
........
r58538 | raymond.hettinger | 2007-10-18 14:13:06 -0700 (Thu, 18 Oct 2007) | 1 line
Remove useless warning
........
r58539 | gregory.p.smith | 2007-10-19 00:31:20 -0700 (Fri, 19 Oct 2007) | 2 lines
squelch the warning that this test is supposed to trigger.
........
r58542 | georg.brandl | 2007-10-19 05:32:39 -0700 (Fri, 19 Oct 2007) | 2 lines
Clarify wording for apply().
........
r58544 | mark.summerfield | 2007-10-19 05:48:17 -0700 (Fri, 19 Oct 2007) | 3 lines
Added a cross-ref to each other.
........
r58545 | georg.brandl | 2007-10-19 10:38:49 -0700 (Fri, 19 Oct 2007) | 2 lines
#1284: "S" means "seen", not unread.
........
r58548 | thomas.heller | 2007-10-19 11:11:41 -0700 (Fri, 19 Oct 2007) | 4 lines
Fix ctypes on 32-bit systems when Python is configured --with-system-ffi.
See also https://bugs.launchpad.net/bugs/72505.
Ported from release25-maint branch.
........
r58550 | facundo.batista | 2007-10-19 12:25:57 -0700 (Fri, 19 Oct 2007) | 8 lines
The constructor from tuple was way too permissive: it allowed bad
coefficient numbers, floats in the sign, and other details that
generated directly the wrong number in the best case, or triggered
misfunctionality in the alorithms.
Test cases added for these issues. Thanks Mark Dickinson.
........
r58559 | georg.brandl | 2007-10-20 06:22:53 -0700 (Sat, 20 Oct 2007) | 2 lines
Fix code being interpreted as a target.
........
r58561 | georg.brandl | 2007-10-20 06:36:24 -0700 (Sat, 20 Oct 2007) | 2 lines
Document new "cmdoption" directive.
........
r58562 | georg.brandl | 2007-10-20 08:21:22 -0700 (Sat, 20 Oct 2007) | 2 lines
Make a path more Unix-standardy.
........
r58564 | georg.brandl | 2007-10-20 10:51:39 -0700 (Sat, 20 Oct 2007) | 2 lines
Document new directive "envvar".
........
r58567 | georg.brandl | 2007-10-20 11:08:14 -0700 (Sat, 20 Oct 2007) | 6 lines
* Add new toplevel chapter, "Using Python." (how to install,
configure and setup python on different platforms -- at least
in theory.)
* Move the Python on Mac docs in that chapter.
* Add a new chapter about the command line invocation, by stargaming.
........
r58568 | georg.brandl | 2007-10-20 11:33:20 -0700 (Sat, 20 Oct 2007) | 2 lines
Change title, for now.
........
r58569 | georg.brandl | 2007-10-20 11:39:25 -0700 (Sat, 20 Oct 2007) | 2 lines
Add entry to ACKS.
........
r58570 | georg.brandl | 2007-10-20 12:05:45 -0700 (Sat, 20 Oct 2007) | 2 lines
Clarify -E docs.
........
r58571 | georg.brandl | 2007-10-20 12:08:36 -0700 (Sat, 20 Oct 2007) | 2 lines
Even more clarification.
........
r58572 | andrew.kuchling | 2007-10-20 12:25:37 -0700 (Sat, 20 Oct 2007) | 1 line
Fix protocol name
........
r58573 | andrew.kuchling | 2007-10-20 12:35:18 -0700 (Sat, 20 Oct 2007) | 1 line
Various items
........
r58574 | andrew.kuchling | 2007-10-20 12:39:35 -0700 (Sat, 20 Oct 2007) | 1 line
Use correct header line
........
r58576 | armin.rigo | 2007-10-21 02:14:15 -0700 (Sun, 21 Oct 2007) | 3 lines
Add a crasher for the long-standing issue with closing a file
while another thread uses it.
........
r58577 | georg.brandl | 2007-10-21 03:01:56 -0700 (Sun, 21 Oct 2007) | 2 lines
Remove duplicate crasher.
........
r58578 | georg.brandl | 2007-10-21 03:24:20 -0700 (Sun, 21 Oct 2007) | 2 lines
Unify "byte code" to "bytecode". Also sprinkle :term: markup for it.
........
r58579 | georg.brandl | 2007-10-21 03:32:54 -0700 (Sun, 21 Oct 2007) | 2 lines
Add markup to new function descriptions.
........
r58580 | georg.brandl | 2007-10-21 03:45:46 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for descriptors.
........
r58581 | georg.brandl | 2007-10-21 03:46:24 -0700 (Sun, 21 Oct 2007) | 2 lines
Unify "file-descriptor" to "file descriptor".
........
r58582 | georg.brandl | 2007-10-21 03:52:38 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term: for generators.
........
r58583 | georg.brandl | 2007-10-21 05:10:28 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for iterator.
........
r58584 | georg.brandl | 2007-10-21 05:15:05 -0700 (Sun, 21 Oct 2007) | 2 lines
Add :term:s for "new-style class".
........
r58588 | neal.norwitz | 2007-10-21 21:47:54 -0700 (Sun, 21 Oct 2007) | 1 line
Add Chris Monson so he can edit PEPs.
........
r58594 | guido.van.rossum | 2007-10-22 09:27:19 -0700 (Mon, 22 Oct 2007) | 4 lines
Issue #1307, patch by Derek Shockey.
When "MAIL" is received without args, an exception happens instead of
sending a 501 syntax error response.
........
r58598 | travis.oliphant | 2007-10-22 19:40:56 -0700 (Mon, 22 Oct 2007) | 1 line
Add phuang patch from Issue 708374 which adds offset parameter to mmap module.
........
r58601 | neal.norwitz | 2007-10-22 22:44:27 -0700 (Mon, 22 Oct 2007) | 2 lines
Bug #1313, fix typo (wrong variable name) in example.
........
r58609 | georg.brandl | 2007-10-23 11:21:35 -0700 (Tue, 23 Oct 2007) | 2 lines
Update Pygments version from externals.
........
r58618 | guido.van.rossum | 2007-10-23 12:25:41 -0700 (Tue, 23 Oct 2007) | 3 lines
Issue 1307 by Derek Shockey, fox the same bug for RCPT.
Neal: please backport!
........
r58620 | raymond.hettinger | 2007-10-23 13:37:41 -0700 (Tue, 23 Oct 2007) | 1 line
Shorter name for namedtuple()
........
r58621 | andrew.kuchling | 2007-10-23 13:55:47 -0700 (Tue, 23 Oct 2007) | 1 line
Update name
........
r58622 | raymond.hettinger | 2007-10-23 14:23:07 -0700 (Tue, 23 Oct 2007) | 1 line
Fixup news entry
........
r58623 | raymond.hettinger | 2007-10-23 18:28:33 -0700 (Tue, 23 Oct 2007) | 1 line
Optimize sum() for integer and float inputs.
........
r58624 | raymond.hettinger | 2007-10-23 19:05:51 -0700 (Tue, 23 Oct 2007) | 1 line
Fixup error return and add support for intermixed ints and floats/
........
r58628 | vinay.sajip | 2007-10-24 03:47:06 -0700 (Wed, 24 Oct 2007) | 1 line
Bug #1321: Fixed logic error in TimedRotatingFileHandler.__init__()
........
r58641 | facundo.batista | 2007-10-24 12:11:08 -0700 (Wed, 24 Oct 2007) | 4 lines
Issue 1290. CharacterData.__repr__ was constructing a string
in response that keeped having a non-ascii character.
........
r58643 | thomas.heller | 2007-10-24 12:50:45 -0700 (Wed, 24 Oct 2007) | 1 line
Added unittest for calling a function with paramflags (backport from py3k branch).
........
r58645 | matthias.klose | 2007-10-24 13:00:44 -0700 (Wed, 24 Oct 2007) | 2 lines
- Build using system ffi library on arm*-linux*.
........
r58651 | georg.brandl | 2007-10-24 14:40:38 -0700 (Wed, 24 Oct 2007) | 2 lines
Bug #1287: make os.environ.pop() work as expected.
........
r58652 | raymond.hettinger | 2007-10-24 19:26:58 -0700 (Wed, 24 Oct 2007) | 1 line
Missing DECREFs
........
r58653 | matthias.klose | 2007-10-24 23:37:24 -0700 (Wed, 24 Oct 2007) | 2 lines
- Build using system ffi library on arm*-linux*, pass --with-system-ffi to CONFIG_ARGS
........
r58655 | thomas.heller | 2007-10-25 12:47:32 -0700 (Thu, 25 Oct 2007) | 2 lines
ffi_type_longdouble may be already #defined.
See issue 1324.
........
r58656 | kurt.kaiser | 2007-10-25 15:43:45 -0700 (Thu, 25 Oct 2007) | 3 lines
Correct an ancient bug in an unused path by removing that path: register() is
now idempotent.
........
r58660 | kurt.kaiser | 2007-10-25 17:10:09 -0700 (Thu, 25 Oct 2007) | 4 lines
1. Add comments to provide top-level documentation.
2. Refactor to use more descriptive names.
3. Enhance tests in main().
........
r58675 | georg.brandl | 2007-10-26 11:30:41 -0700 (Fri, 26 Oct 2007) | 2 lines
Fix new pop() method on os.environ on ignorecase-platforms.
........
r58696 | neal.norwitz | 2007-10-27 15:32:21 -0700 (Sat, 27 Oct 2007) | 1 line
Update URL for Pygments. 0.8.1 is no longer available
........
r58697 | hyeshik.chang | 2007-10-28 04:19:02 -0700 (Sun, 28 Oct 2007) | 3 lines
- Add support for FreeBSD 8 which is recently forked from FreeBSD 7.
- Regenerate IN module for most recent maintenance tree of FreeBSD 6 and 7.
........
r58698 | hyeshik.chang | 2007-10-28 05:38:09 -0700 (Sun, 28 Oct 2007) | 2 lines
Enable platform-specific tweaks for FreeBSD 8 (exactly same to FreeBSD 7's yet)
........
r58700 | kurt.kaiser | 2007-10-28 12:03:59 -0700 (Sun, 28 Oct 2007) | 2 lines
Add confirmation dialog before printing. Patch 1717170 Tal Einat.
........
r58706 | guido.van.rossum | 2007-10-29 13:52:45 -0700 (Mon, 29 Oct 2007) | 3 lines
Patch 1353 by Jacob Winther.
Add mp4 mapping to mimetypes.py.
........
r58709 | guido.van.rossum | 2007-10-29 15:15:05 -0700 (Mon, 29 Oct 2007) | 6 lines
Backport fixes for the code that decodes octal escapes (and for PyString
also hex escapes) -- this was reaching beyond the end of the input string
buffer, even though it is not supposed to be \0-terminated.
This has no visible effect but is clearly the correct thing to do.
(In 3.0 it had a visible effect after removing ob_sstate from PyString.)
........
r58710 | kurt.kaiser | 2007-10-29 19:38:54 -0700 (Mon, 29 Oct 2007) | 7 lines
check in Tal Einat's update to tabpage.py
Patch 1612746
M configDialog.py
M NEWS.txt
AM tabbedpages.py
........
r58715 | georg.brandl | 2007-10-30 10:51:18 -0700 (Tue, 30 Oct 2007) | 2 lines
Use correct markup.
........
r58716 | georg.brandl | 2007-10-30 10:57:12 -0700 (Tue, 30 Oct 2007) | 2 lines
Make example about hiding None return values at the prompt clearer.
........
r58728 | neal.norwitz | 2007-10-30 23:33:20 -0700 (Tue, 30 Oct 2007) | 1 line
Fix some compiler warnings for signed comparisons on Unix and Windows.
........
r58731 | martin.v.loewis | 2007-10-31 10:19:33 -0700 (Wed, 31 Oct 2007) | 2 lines
Adding Christian Heimes.
........
r58737 | raymond.hettinger | 2007-10-31 14:57:58 -0700 (Wed, 31 Oct 2007) | 1 line
Clarify the reasons why pickle is almost always better than marshal
........
r58739 | raymond.hettinger | 2007-10-31 15:15:49 -0700 (Wed, 31 Oct 2007) | 1 line
Sets are marshalable.
........
2007-11-01 17:32:30 -03:00
|
|
|
Exit the runtime context and return a Boolean flag indicating if any exception
|
2007-08-15 11:28:22 -03:00
|
|
|
that occurred should be suppressed. If an exception occurred while executing the
|
|
|
|
body of the :keyword:`with` statement, the arguments contain the exception type,
|
|
|
|
value and traceback information. Otherwise, all three arguments are ``None``.
|
|
|
|
|
|
|
|
Returning a true value from this method will cause the :keyword:`with` statement
|
|
|
|
to suppress the exception and continue execution with the statement immediately
|
|
|
|
following the :keyword:`with` statement. Otherwise the exception continues
|
|
|
|
propagating after this method has finished executing. Exceptions that occur
|
|
|
|
during execution of this method will replace any exception that occurred in the
|
|
|
|
body of the :keyword:`with` statement.
|
|
|
|
|
|
|
|
The exception passed in should never be reraised explicitly - instead, this
|
|
|
|
method should return a false value to indicate that the method completed
|
|
|
|
successfully and does not want to suppress the raised exception. This allows
|
2014-10-31 05:41:46 -03:00
|
|
|
context management code to easily detect whether or not an :meth:`__exit__`
|
|
|
|
method has actually failed.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Python defines several context managers to support easy thread synchronisation,
|
|
|
|
prompt closure of files or other objects, and simpler manipulation of the active
|
|
|
|
decimal arithmetic context. The specific types are not treated specially beyond
|
|
|
|
their implementation of the context management protocol. See the
|
|
|
|
:mod:`contextlib` module for some examples.
|
|
|
|
|
2010-12-12 16:09:18 -04:00
|
|
|
Python's :term:`generator`\s and the :class:`contextlib.contextmanager` decorator
|
Merged revisions 59259-59274 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59260 | lars.gustaebel | 2007-12-01 22:02:12 +0100 (Sat, 01 Dec 2007) | 5 lines
Issue #1531: Read fileobj from the current offset, do not seek to
the start.
(will backport to 2.5)
........
r59262 | georg.brandl | 2007-12-01 23:24:47 +0100 (Sat, 01 Dec 2007) | 4 lines
Document PyEval_* functions from ceval.c.
Credits to Michael Sloan from GHOP.
........
r59263 | georg.brandl | 2007-12-01 23:27:56 +0100 (Sat, 01 Dec 2007) | 2 lines
Add a few refcount data entries.
........
r59264 | georg.brandl | 2007-12-01 23:38:48 +0100 (Sat, 01 Dec 2007) | 4 lines
Add test suite for cmd module.
Written by Michael Schneider for GHOP.
........
r59265 | georg.brandl | 2007-12-01 23:42:46 +0100 (Sat, 01 Dec 2007) | 3 lines
Add examples to the ElementTree documentation.
Written by h4wk.cz for GHOP.
........
r59266 | georg.brandl | 2007-12-02 00:12:45 +0100 (Sun, 02 Dec 2007) | 3 lines
Add "Using Python on Windows" document, by Robert Lehmann.
Written for GHOP.
........
r59271 | georg.brandl | 2007-12-02 15:34:34 +0100 (Sun, 02 Dec 2007) | 3 lines
Add example to mmap docs.
Written for GHOP by Rafal Rawicki.
........
r59272 | georg.brandl | 2007-12-02 15:37:29 +0100 (Sun, 02 Dec 2007) | 2 lines
Convert bdb.rst line endings to Unix style.
........
r59274 | georg.brandl | 2007-12-02 15:58:50 +0100 (Sun, 02 Dec 2007) | 4 lines
Add more entries to the glossary.
Written by Jeff Wheeler for GHOP.
........
2007-12-02 11:22:16 -04:00
|
|
|
provide a convenient way to implement these protocols. If a generator function is
|
2010-12-12 16:09:18 -04:00
|
|
|
decorated with the :class:`contextlib.contextmanager` decorator, it will return a
|
2007-08-15 11:28:22 -03:00
|
|
|
context manager implementing the necessary :meth:`__enter__` and
|
|
|
|
:meth:`__exit__` methods, rather than the iterator produced by an undecorated
|
|
|
|
generator function.
|
|
|
|
|
|
|
|
Note that there is no specific slot for any of these methods in the type
|
|
|
|
structure for Python objects in the Python/C API. Extension types wanting to
|
|
|
|
define these methods must provide them as a normal Python accessible method.
|
|
|
|
Compared to the overhead of setting up the runtime context, the overhead of a
|
|
|
|
single class dictionary lookup is negligible.
|
|
|
|
|
|
|
|
|
|
|
|
.. _typesother:
|
|
|
|
|
|
|
|
Other Built-in Types
|
|
|
|
====================
|
|
|
|
|
|
|
|
The interpreter supports several other kinds of objects. Most of these support
|
|
|
|
only one or two operations.
|
|
|
|
|
|
|
|
|
|
|
|
.. _typesmodules:
|
|
|
|
|
|
|
|
Modules
|
|
|
|
-------
|
|
|
|
|
|
|
|
The only special operation on a module is attribute access: ``m.name``, where
|
|
|
|
*m* is a module and *name* accesses a name defined in *m*'s symbol table.
|
|
|
|
Module attributes can be assigned to. (Note that the :keyword:`import`
|
|
|
|
statement is not, strictly speaking, an operation on a module object; ``import
|
|
|
|
foo`` does not require a module object named *foo* to exist, rather it requires
|
|
|
|
an (external) *definition* for a module named *foo* somewhere.)
|
|
|
|
|
2013-10-09 08:02:31 -03:00
|
|
|
A special attribute of every module is :attr:`~object.__dict__`. This is the
|
|
|
|
dictionary containing the module's symbol table. Modifying this dictionary will
|
|
|
|
actually change the module's symbol table, but direct assignment to the
|
2016-06-18 00:57:31 -03:00
|
|
|
:attr:`~object.__dict__` attribute is not possible (you can write
|
2013-10-09 08:02:31 -03:00
|
|
|
``m.__dict__['a'] = 1``, which defines ``m.a`` to be ``1``, but you can't write
|
2016-06-18 00:57:31 -03:00
|
|
|
``m.__dict__ = {}``). Modifying :attr:`~object.__dict__` directly is
|
|
|
|
not recommended.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Modules built into the interpreter are written like this: ``<module 'sys'
|
|
|
|
(built-in)>``. If loaded from a file, they are written as ``<module 'os' from
|
|
|
|
'/usr/local/lib/pythonX.Y/os.pyc'>``.
|
|
|
|
|
|
|
|
|
|
|
|
.. _typesobjects:
|
|
|
|
|
|
|
|
Classes and Class Instances
|
|
|
|
---------------------------
|
|
|
|
|
|
|
|
See :ref:`objects` and :ref:`class` for these.
|
|
|
|
|
|
|
|
|
|
|
|
.. _typesfunctions:
|
|
|
|
|
|
|
|
Functions
|
|
|
|
---------
|
|
|
|
|
|
|
|
Function objects are created by function definitions. The only operation on a
|
|
|
|
function object is to call it: ``func(argument-list)``.
|
|
|
|
|
|
|
|
There are really two flavors of function objects: built-in functions and
|
|
|
|
user-defined functions. Both support the same operation (to call the function),
|
|
|
|
but the implementation is different, hence the different object types.
|
|
|
|
|
|
|
|
See :ref:`function` for more information.
|
|
|
|
|
|
|
|
|
|
|
|
.. _typesmethods:
|
|
|
|
|
|
|
|
Methods
|
|
|
|
-------
|
|
|
|
|
|
|
|
.. index:: object: method
|
|
|
|
|
|
|
|
Methods are functions that are called using the attribute notation. There are
|
|
|
|
two flavors: built-in methods (such as :meth:`append` on lists) and class
|
|
|
|
instance methods. Built-in methods are described with the types that support
|
|
|
|
them.
|
|
|
|
|
2007-11-27 08:43:08 -04:00
|
|
|
If you access a method (a function defined in a class namespace) through an
|
|
|
|
instance, you get a special object: a :dfn:`bound method` (also called
|
|
|
|
:dfn:`instance method`) object. When called, it will add the ``self`` argument
|
|
|
|
to the argument list. Bound methods have two special read-only attributes:
|
|
|
|
``m.__self__`` is the object on which the method operates, and ``m.__func__`` is
|
|
|
|
the function implementing the method. Calling ``m(arg-1, arg-2, ..., arg-n)``
|
|
|
|
is completely equivalent to calling ``m.__func__(m.__self__, arg-1, arg-2, ...,
|
|
|
|
arg-n)``.
|
|
|
|
|
|
|
|
Like function objects, bound method objects support getting arbitrary
|
|
|
|
attributes. However, since method attributes are actually stored on the
|
|
|
|
underlying function object (``meth.__func__``), setting method attributes on
|
2012-11-08 19:08:25 -04:00
|
|
|
bound methods is disallowed. Attempting to set an attribute on a method
|
|
|
|
results in an :exc:`AttributeError` being raised. In order to set a method
|
|
|
|
attribute, you need to explicitly set it on the underlying function object::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-11-08 19:08:25 -04:00
|
|
|
>>> class C:
|
|
|
|
... def method(self):
|
|
|
|
... pass
|
|
|
|
...
|
|
|
|
>>> c = C()
|
|
|
|
>>> c.method.whoami = 'my name is method' # can't set on the method
|
|
|
|
Traceback (most recent call last):
|
|
|
|
File "<stdin>", line 1, in <module>
|
|
|
|
AttributeError: 'method' object has no attribute 'whoami'
|
|
|
|
>>> c.method.__func__.whoami = 'my name is method'
|
|
|
|
>>> c.method.whoami
|
|
|
|
'my name is method'
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
See :ref:`types` for more information.
|
|
|
|
|
|
|
|
|
2016-06-02 20:26:51 -03:00
|
|
|
.. index:: object; code, code object
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. _bltin-code-objects:
|
|
|
|
|
|
|
|
Code Objects
|
|
|
|
------------
|
|
|
|
|
|
|
|
.. index::
|
|
|
|
builtin: compile
|
|
|
|
single: __code__ (function object attribute)
|
|
|
|
|
|
|
|
Code objects are used by the implementation to represent "pseudo-compiled"
|
|
|
|
executable Python code such as a function body. They differ from function
|
|
|
|
objects because they don't contain a reference to their global execution
|
|
|
|
environment. Code objects are returned by the built-in :func:`compile` function
|
|
|
|
and can be extracted from function objects through their :attr:`__code__`
|
|
|
|
attribute. See also the :mod:`code` module.
|
|
|
|
|
|
|
|
.. index::
|
|
|
|
builtin: exec
|
|
|
|
builtin: eval
|
|
|
|
|
|
|
|
A code object can be executed or evaluated by passing it (instead of a source
|
|
|
|
string) to the :func:`exec` or :func:`eval` built-in functions.
|
|
|
|
|
|
|
|
See :ref:`types` for more information.
|
|
|
|
|
|
|
|
|
|
|
|
.. _bltin-type-objects:
|
|
|
|
|
|
|
|
Type Objects
|
|
|
|
------------
|
|
|
|
|
|
|
|
.. index::
|
|
|
|
builtin: type
|
|
|
|
module: types
|
|
|
|
|
|
|
|
Type objects represent the various object types. An object's type is accessed
|
|
|
|
by the built-in function :func:`type`. There are no special operations on
|
|
|
|
types. The standard module :mod:`types` defines names for all standard built-in
|
|
|
|
types.
|
|
|
|
|
2008-04-07 02:43:42 -03:00
|
|
|
Types are written like this: ``<class 'int'>``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. _bltin-null-object:
|
|
|
|
|
|
|
|
The Null Object
|
|
|
|
---------------
|
|
|
|
|
|
|
|
This object is returned by functions that don't explicitly return a value. It
|
|
|
|
supports no special operations. There is exactly one null object, named
|
2011-07-30 14:26:27 -03:00
|
|
|
``None`` (a built-in name). ``type(None)()`` produces the same singleton.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
It is written as ``None``.
|
|
|
|
|
|
|
|
|
|
|
|
.. _bltin-ellipsis-object:
|
|
|
|
|
|
|
|
The Ellipsis Object
|
|
|
|
-------------------
|
|
|
|
|
2012-05-15 02:09:31 -03:00
|
|
|
This object is commonly used by slicing (see :ref:`slicings`). It supports no
|
|
|
|
special operations. There is exactly one ellipsis object, named
|
|
|
|
:const:`Ellipsis` (a built-in name). ``type(Ellipsis)()`` produces the
|
|
|
|
:const:`Ellipsis` singleton.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
It is written as ``Ellipsis`` or ``...``.
|
|
|
|
|
|
|
|
|
2011-09-01 18:10:36 -03:00
|
|
|
.. _bltin-notimplemented-object:
|
|
|
|
|
2011-07-30 11:57:24 -03:00
|
|
|
The NotImplemented Object
|
|
|
|
-------------------------
|
|
|
|
|
|
|
|
This object is returned from comparisons and binary operations when they are
|
|
|
|
asked to operate on types they don't support. See :ref:`comparisons` for more
|
2011-07-30 14:26:27 -03:00
|
|
|
information. There is exactly one ``NotImplemented`` object.
|
|
|
|
``type(NotImplemented)()`` produces the singleton instance.
|
2011-07-30 11:57:24 -03:00
|
|
|
|
|
|
|
It is written as ``NotImplemented``.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-09-01 18:10:36 -03:00
|
|
|
.. _bltin-boolean-values:
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
Boolean Values
|
|
|
|
--------------
|
|
|
|
|
|
|
|
Boolean values are the two constant objects ``False`` and ``True``. They are
|
|
|
|
used to represent truth values (although other values can also be considered
|
|
|
|
false or true). In numeric contexts (for example when used as the argument to
|
|
|
|
an arithmetic operator), they behave like the integers 0 and 1, respectively.
|
2011-12-02 13:47:24 -04:00
|
|
|
The built-in function :func:`bool` can be used to convert any value to a
|
|
|
|
Boolean, if the value can be interpreted as a truth value (see section
|
|
|
|
:ref:`truth` above).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. index::
|
|
|
|
single: False
|
|
|
|
single: True
|
|
|
|
pair: Boolean; values
|
|
|
|
|
|
|
|
They are written as ``False`` and ``True``, respectively.
|
|
|
|
|
|
|
|
|
|
|
|
.. _typesinternal:
|
|
|
|
|
|
|
|
Internal Objects
|
|
|
|
----------------
|
|
|
|
|
|
|
|
See :ref:`types` for this information. It describes stack frame objects,
|
|
|
|
traceback objects, and slice objects.
|
|
|
|
|
|
|
|
|
|
|
|
.. _specialattrs:
|
|
|
|
|
|
|
|
Special Attributes
|
|
|
|
==================
|
|
|
|
|
|
|
|
The implementation adds a few special read-only attributes to several object
|
|
|
|
types, where they are relevant. Some of these are not reported by the
|
|
|
|
:func:`dir` built-in function.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: object.__dict__
|
|
|
|
|
|
|
|
A dictionary or other mapping object used to store an object's (writable)
|
|
|
|
attributes.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: instance.__class__
|
|
|
|
|
|
|
|
The class to which a class instance belongs.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: class.__bases__
|
|
|
|
|
Merged revisions 76847,76851,76869,76882,76891-76892,76924,77007,77070,77092,77096,77120,77126,77155 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r76847 | benjamin.peterson | 2009-12-14 21:25:27 -0600 (Mon, 14 Dec 2009) | 1 line
adverb
........
r76851 | benjamin.peterson | 2009-12-15 21:28:52 -0600 (Tue, 15 Dec 2009) | 1 line
remove lib2to3 resource
........
r76869 | vinay.sajip | 2009-12-17 08:52:00 -0600 (Thu, 17 Dec 2009) | 1 line
Issue #7529: logging: Minor correction to documentation.
........
r76882 | georg.brandl | 2009-12-19 11:30:28 -0600 (Sat, 19 Dec 2009) | 1 line
#7527: use standard versionadded tags.
........
r76891 | georg.brandl | 2009-12-19 12:16:31 -0600 (Sat, 19 Dec 2009) | 1 line
#7479: add note about function availability on Unices.
........
r76892 | georg.brandl | 2009-12-19 12:20:18 -0600 (Sat, 19 Dec 2009) | 1 line
#7480: remove tautology.
........
r76924 | georg.brandl | 2009-12-20 08:28:05 -0600 (Sun, 20 Dec 2009) | 1 line
Small indentation fix.
........
r77007 | gregory.p.smith | 2009-12-23 03:31:11 -0600 (Wed, 23 Dec 2009) | 3 lines
Fix possible integer overflow in lchown and fchown functions. For issue1747858.
........
r77070 | amaury.forgeotdarc | 2009-12-27 14:06:44 -0600 (Sun, 27 Dec 2009) | 2 lines
Fix a typo in comment
........
r77092 | georg.brandl | 2009-12-28 02:48:24 -0600 (Mon, 28 Dec 2009) | 1 line
#7404: remove reference to non-existing example files.
........
r77096 | benjamin.peterson | 2009-12-28 14:51:17 -0600 (Mon, 28 Dec 2009) | 1 line
document new fix_callable behavior
........
r77120 | georg.brandl | 2009-12-29 15:09:17 -0600 (Tue, 29 Dec 2009) | 1 line
#7595: fix typo in argument default constant.
........
r77126 | amaury.forgeotdarc | 2009-12-29 17:06:17 -0600 (Tue, 29 Dec 2009) | 2 lines
#7579: Add docstrings to the msvcrt module
........
r77155 | georg.brandl | 2009-12-30 13:03:00 -0600 (Wed, 30 Dec 2009) | 1 line
We only support Windows NT derivatives now.
........
2009-12-30 23:11:23 -04:00
|
|
|
The tuple of base classes of a class object.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2016-06-18 00:57:31 -03:00
|
|
|
.. attribute:: definition.__name__
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2016-06-18 00:57:31 -03:00
|
|
|
The name of the class, function, method, descriptor, or
|
|
|
|
generator instance.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2009-03-28 16:13:21 -03:00
|
|
|
|
2016-06-18 00:57:31 -03:00
|
|
|
.. attribute:: definition.__qualname__
|
2011-11-25 13:56:07 -04:00
|
|
|
|
2016-06-18 00:57:31 -03:00
|
|
|
The :term:`qualified name` of the class, function, method, descriptor,
|
|
|
|
or generator instance.
|
2011-11-25 13:56:07 -04:00
|
|
|
|
|
|
|
.. versionadded:: 3.3
|
|
|
|
|
|
|
|
|
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r70712 | benjamin.peterson | 2009-03-30 10:15:38 -0500 (Mon, 30 Mar 2009) | 1 line
don't rely on the order dict repr #5605
........
r70714 | brett.cannon | 2009-03-30 10:20:53 -0500 (Mon, 30 Mar 2009) | 1 line
Add an entry to developers.txt.
........
r70764 | martin.v.loewis | 2009-03-30 17:06:33 -0500 (Mon, 30 Mar 2009) | 2 lines
Add several VM developers.
........
r70765 | georg.brandl | 2009-03-30 17:09:34 -0500 (Mon, 30 Mar 2009) | 1 line
#5199: make warning about vars() assignment more visible.
........
r70769 | andrew.kuchling | 2009-03-30 17:29:53 -0500 (Mon, 30 Mar 2009) | 1 line
Remove comment
........
r70770 | andrew.kuchling | 2009-03-30 17:30:20 -0500 (Mon, 30 Mar 2009) | 1 line
Add several items and placeholders
........
r70771 | andrew.kuchling | 2009-03-30 17:31:11 -0500 (Mon, 30 Mar 2009) | 1 line
Many edits
........
r70773 | georg.brandl | 2009-03-30 17:43:00 -0500 (Mon, 30 Mar 2009) | 1 line
#5039: make it clear that the impl. note refers to CPython.
........
r70776 | andrew.kuchling | 2009-03-30 18:08:24 -0500 (Mon, 30 Mar 2009) | 1 line
typo fix
........
r70777 | andrew.kuchling | 2009-03-30 18:09:46 -0500 (Mon, 30 Mar 2009) | 1 line
Add more items
........
r70788 | andrew.kuchling | 2009-03-30 20:21:01 -0500 (Mon, 30 Mar 2009) | 1 line
Add various items
........
r70789 | georg.brandl | 2009-03-30 20:25:15 -0500 (Mon, 30 Mar 2009) | 1 line
Fix a wrong struct field assignment (docstring as closure).
........
r70824 | georg.brandl | 2009-03-31 10:43:20 -0500 (Tue, 31 Mar 2009) | 1 line
#5519: remove reference to Kodos, which seems dead.
........
r70828 | georg.brandl | 2009-03-31 10:50:16 -0500 (Tue, 31 Mar 2009) | 1 line
#5581: fget argument of abstractproperty is optional as well.
........
r70832 | georg.brandl | 2009-03-31 11:31:11 -0500 (Tue, 31 Mar 2009) | 1 line
#1386675: specify WindowsError as the exception, because it has a winerror attribute that EnvironmentError doesnt have.
........
r70836 | georg.brandl | 2009-03-31 11:50:25 -0500 (Tue, 31 Mar 2009) | 1 line
#5417: replace references to undocumented functions by ones to documented functions.
........
r70842 | georg.brandl | 2009-03-31 12:13:06 -0500 (Tue, 31 Mar 2009) | 1 line
#970783: document PyObject_Generic[GS]etAttr.
........
r70851 | georg.brandl | 2009-03-31 13:26:55 -0500 (Tue, 31 Mar 2009) | 1 line
#837577: note cryptic return value of spawn*e on invalid env dicts.
........
r70855 | georg.brandl | 2009-03-31 13:30:37 -0500 (Tue, 31 Mar 2009) | 1 line
#5245: note that PyRun_SimpleString doesnt return on SystemExit.
........
r70857 | georg.brandl | 2009-03-31 13:33:10 -0500 (Tue, 31 Mar 2009) | 1 line
#5227: note that Py_Main doesnt return on SystemExit.
........
r70866 | georg.brandl | 2009-03-31 14:06:57 -0500 (Tue, 31 Mar 2009) | 1 line
#4882: document named group behavior a bit better.
........
r70867 | georg.brandl | 2009-03-31 14:10:35 -0500 (Tue, 31 Mar 2009) | 1 line
#1096310: document usage of sys.__std*__ a bit better.
........
r70868 | georg.brandl | 2009-03-31 14:12:17 -0500 (Tue, 31 Mar 2009) | 1 line
#5190: export make_option in __all__.
........
r70869 | georg.brandl | 2009-03-31 14:14:42 -0500 (Tue, 31 Mar 2009) | 1 line
Fix-up unwanted change.
........
r70870 | georg.brandl | 2009-03-31 14:26:24 -0500 (Tue, 31 Mar 2009) | 1 line
#4411: document mro() and __mro__. (I hope I got it right.)
........
r70871 | georg.brandl | 2009-03-31 14:30:56 -0500 (Tue, 31 Mar 2009) | 1 line
#5618: fix typo.
........
r70872 | r.david.murray | 2009-03-31 14:31:17 -0500 (Tue, 31 Mar 2009) | 3 lines
Delete out-of-date and little-known README from the test
directory by consensus of devs at pycon sprint.
........
r70883 | georg.brandl | 2009-03-31 15:41:08 -0500 (Tue, 31 Mar 2009) | 1 line
#1674032: return value of flag from Event.wait(). OKed by Guido.
........
r70885 | tarek.ziade | 2009-03-31 15:48:31 -0500 (Tue, 31 Mar 2009) | 1 line
using log.warn for sys.stderr
........
r70893 | georg.brandl | 2009-03-31 15:56:32 -0500 (Tue, 31 Mar 2009) | 1 line
#1530012: move TQS section before raw strings.
........
r70894 | benjamin.peterson | 2009-03-31 16:06:30 -0500 (Tue, 31 Mar 2009) | 1 line
take the usual lock precautions around _active_limbo_lock
........
r70896 | georg.brandl | 2009-03-31 16:15:33 -0500 (Tue, 31 Mar 2009) | 1 line
#5598: document DocFileSuite *args argument.
........
r70897 | benjamin.peterson | 2009-03-31 16:34:42 -0500 (Tue, 31 Mar 2009) | 1 line
fix Thread.ident when it is the main thread or a dummy thread #5632
........
r70903 | georg.brandl | 2009-03-31 16:45:18 -0500 (Tue, 31 Mar 2009) | 1 line
#1676135: remove trailing slashes from --prefix argument.
........
r70905 | georg.brandl | 2009-03-31 17:03:40 -0500 (Tue, 31 Mar 2009) | 1 line
#5563: more documentation for bdist_msi.
........
r70906 | georg.brandl | 2009-03-31 17:11:53 -0500 (Tue, 31 Mar 2009) | 1 line
#1651995: fix _convert_ref for non-ASCII characters.
........
r70907 | georg.brandl | 2009-03-31 17:18:19 -0500 (Tue, 31 Mar 2009) | 1 line
#3427: document correct return type for urlopen().info().
........
r70915 | georg.brandl | 2009-03-31 17:40:16 -0500 (Tue, 31 Mar 2009) | 1 line
#5018: remove confusing paragraph.
........
r70927 | georg.brandl | 2009-03-31 18:01:27 -0500 (Tue, 31 Mar 2009) | 1 line
Dont shout to users.
........
r70933 | georg.brandl | 2009-03-31 19:04:33 -0500 (Tue, 31 Mar 2009) | 2 lines
Issue #5635: Fix running test_sys with tracing enabled.
........
r70951 | georg.brandl | 2009-04-01 09:02:27 -0500 (Wed, 01 Apr 2009) | 1 line
Add Maksim, who worked on several issues at the sprint.
........
r70960 | jesse.noller | 2009-04-01 11:42:19 -0500 (Wed, 01 Apr 2009) | 1 line
Issue 3270: document Listener address restrictions on windows
........
r70962 | brett.cannon | 2009-04-01 12:07:16 -0500 (Wed, 01 Apr 2009) | 2 lines
Ron DuPlain was given commit privileges at PyCon 2009 to work on 3to2.
........
r70963 | georg.brandl | 2009-04-01 12:46:01 -0500 (Wed, 01 Apr 2009) | 1 line
#5655: fix docstring oversight.
........
r70964 | brett.cannon | 2009-04-01 12:52:13 -0500 (Wed, 01 Apr 2009) | 2 lines
Paul Kippes was given commit privileges to work on 3to2.
........
r70998 | georg.brandl | 2009-04-01 16:54:21 -0500 (Wed, 01 Apr 2009) | 1 line
In Pdb, stop assigning values to __builtin__._ which interferes with the one commonly installed by gettext.
........
r71001 | brett.cannon | 2009-04-01 18:01:12 -0500 (Wed, 01 Apr 2009) | 3 lines
Add my initials to Misc/developers.txt. Names are now sorted by number of
characters in the person's name.
........
r71006 | georg.brandl | 2009-04-01 18:32:17 -0500 (Wed, 01 Apr 2009) | 1 line
Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
........
r71008 | andrew.kuchling | 2009-04-01 19:02:14 -0500 (Wed, 01 Apr 2009) | 1 line
Typo fix
........
r71010 | benjamin.peterson | 2009-04-01 19:11:52 -0500 (Wed, 01 Apr 2009) | 1 line
fix markup
........
r71011 | benjamin.peterson | 2009-04-01 19:12:47 -0500 (Wed, 01 Apr 2009) | 1 line
this should be :noindex:
........
r71019 | georg.brandl | 2009-04-01 21:00:01 -0500 (Wed, 01 Apr 2009) | 1 line
Fix test_doctest, missed two assignments to curframe.
........
r71037 | r.david.murray | 2009-04-01 23:34:04 -0500 (Wed, 01 Apr 2009) | 6 lines
Clarify that datetime strftime does not produce leap seconds and datetime
strptime does not accept it in the strftime behavior section of the
datetime docs.
Closes issue 2568.
........
r71056 | georg.brandl | 2009-04-02 12:43:07 -0500 (Thu, 02 Apr 2009) | 2 lines
Actually the displayhook should print the repr.
........
r71094 | vinay.sajip | 2009-04-03 05:23:18 -0500 (Fri, 03 Apr 2009) | 1 line
Added warning about logging use from asynchronous signal handlers.
........
r71101 | andrew.kuchling | 2009-04-03 16:43:00 -0500 (Fri, 03 Apr 2009) | 1 line
Add some items
........
r71102 | andrew.kuchling | 2009-04-03 16:44:49 -0500 (Fri, 03 Apr 2009) | 1 line
Fix 'the the'; grammar fix
........
r71103 | andrew.kuchling | 2009-04-03 16:45:29 -0500 (Fri, 03 Apr 2009) | 1 line
Fix 'the the' duplication
........
r71106 | vinay.sajip | 2009-04-03 16:58:16 -0500 (Fri, 03 Apr 2009) | 1 line
Clarified warning about logging use from asynchronous signal handlers.
........
r71119 | raymond.hettinger | 2009-04-04 00:37:47 -0500 (Sat, 04 Apr 2009) | 1 line
Add helpful link.
........
r71123 | r.david.murray | 2009-04-04 01:39:56 -0500 (Sat, 04 Apr 2009) | 2 lines
Fix error in description of 'oct' (issue 5678).
........
r71149 | georg.brandl | 2009-04-04 08:42:39 -0500 (Sat, 04 Apr 2009) | 1 line
#5642: clarify map() compatibility to the builtin.
........
r71150 | georg.brandl | 2009-04-04 08:45:49 -0500 (Sat, 04 Apr 2009) | 1 line
#5601: clarify that webbrowser is not meant for file names.
........
r71203 | benjamin.peterson | 2009-04-04 18:46:34 -0500 (Sat, 04 Apr 2009) | 1 line
note how using iter* are unsafe while mutating and document iter(dict)
........
r71212 | georg.brandl | 2009-04-05 05:24:20 -0500 (Sun, 05 Apr 2009) | 1 line
#1742837: expand HTTP server docs, and fix SocketServer ones to document methods as methods, not functions.
........
r71214 | georg.brandl | 2009-04-05 05:29:57 -0500 (Sun, 05 Apr 2009) | 1 line
Normalize spelling of Mac OS X.
........
r71215 | georg.brandl | 2009-04-05 05:32:26 -0500 (Sun, 05 Apr 2009) | 1 line
Avoid sure signs of a diseased mind.
........
r71216 | georg.brandl | 2009-04-05 05:41:02 -0500 (Sun, 05 Apr 2009) | 1 line
#1718017: document the relation of os.path and the posixpath, ntpath etc. modules better.
........
r71217 | georg.brandl | 2009-04-05 05:48:47 -0500 (Sun, 05 Apr 2009) | 1 line
#1726172: dont raise an unexpected IndexError if a voidresp() call has an empty response.
........
r71221 | vinay.sajip | 2009-04-05 06:06:24 -0500 (Sun, 05 Apr 2009) | 1 line
Issue #5695: Moved logging.captureWarnings() call inside with statement in WarningsTest.test_warnings.
........
r71240 | georg.brandl | 2009-04-05 09:40:06 -0500 (Sun, 05 Apr 2009) | 1 line
#5370: doc update about unpickling objects with custom __getattr__ etc. methods.
........
2009-04-05 16:13:16 -03:00
|
|
|
.. attribute:: class.__mro__
|
|
|
|
|
|
|
|
This attribute is a tuple of classes that are considered when looking for
|
|
|
|
base classes during method resolution.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: class.mro()
|
|
|
|
|
|
|
|
This method can be overridden by a metaclass to customize the method
|
|
|
|
resolution order for its instances. It is called at class instantiation, and
|
2013-10-09 08:02:31 -03:00
|
|
|
its result is stored in :attr:`~class.__mro__`.
|
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r70712 | benjamin.peterson | 2009-03-30 10:15:38 -0500 (Mon, 30 Mar 2009) | 1 line
don't rely on the order dict repr #5605
........
r70714 | brett.cannon | 2009-03-30 10:20:53 -0500 (Mon, 30 Mar 2009) | 1 line
Add an entry to developers.txt.
........
r70764 | martin.v.loewis | 2009-03-30 17:06:33 -0500 (Mon, 30 Mar 2009) | 2 lines
Add several VM developers.
........
r70765 | georg.brandl | 2009-03-30 17:09:34 -0500 (Mon, 30 Mar 2009) | 1 line
#5199: make warning about vars() assignment more visible.
........
r70769 | andrew.kuchling | 2009-03-30 17:29:53 -0500 (Mon, 30 Mar 2009) | 1 line
Remove comment
........
r70770 | andrew.kuchling | 2009-03-30 17:30:20 -0500 (Mon, 30 Mar 2009) | 1 line
Add several items and placeholders
........
r70771 | andrew.kuchling | 2009-03-30 17:31:11 -0500 (Mon, 30 Mar 2009) | 1 line
Many edits
........
r70773 | georg.brandl | 2009-03-30 17:43:00 -0500 (Mon, 30 Mar 2009) | 1 line
#5039: make it clear that the impl. note refers to CPython.
........
r70776 | andrew.kuchling | 2009-03-30 18:08:24 -0500 (Mon, 30 Mar 2009) | 1 line
typo fix
........
r70777 | andrew.kuchling | 2009-03-30 18:09:46 -0500 (Mon, 30 Mar 2009) | 1 line
Add more items
........
r70788 | andrew.kuchling | 2009-03-30 20:21:01 -0500 (Mon, 30 Mar 2009) | 1 line
Add various items
........
r70789 | georg.brandl | 2009-03-30 20:25:15 -0500 (Mon, 30 Mar 2009) | 1 line
Fix a wrong struct field assignment (docstring as closure).
........
r70824 | georg.brandl | 2009-03-31 10:43:20 -0500 (Tue, 31 Mar 2009) | 1 line
#5519: remove reference to Kodos, which seems dead.
........
r70828 | georg.brandl | 2009-03-31 10:50:16 -0500 (Tue, 31 Mar 2009) | 1 line
#5581: fget argument of abstractproperty is optional as well.
........
r70832 | georg.brandl | 2009-03-31 11:31:11 -0500 (Tue, 31 Mar 2009) | 1 line
#1386675: specify WindowsError as the exception, because it has a winerror attribute that EnvironmentError doesnt have.
........
r70836 | georg.brandl | 2009-03-31 11:50:25 -0500 (Tue, 31 Mar 2009) | 1 line
#5417: replace references to undocumented functions by ones to documented functions.
........
r70842 | georg.brandl | 2009-03-31 12:13:06 -0500 (Tue, 31 Mar 2009) | 1 line
#970783: document PyObject_Generic[GS]etAttr.
........
r70851 | georg.brandl | 2009-03-31 13:26:55 -0500 (Tue, 31 Mar 2009) | 1 line
#837577: note cryptic return value of spawn*e on invalid env dicts.
........
r70855 | georg.brandl | 2009-03-31 13:30:37 -0500 (Tue, 31 Mar 2009) | 1 line
#5245: note that PyRun_SimpleString doesnt return on SystemExit.
........
r70857 | georg.brandl | 2009-03-31 13:33:10 -0500 (Tue, 31 Mar 2009) | 1 line
#5227: note that Py_Main doesnt return on SystemExit.
........
r70866 | georg.brandl | 2009-03-31 14:06:57 -0500 (Tue, 31 Mar 2009) | 1 line
#4882: document named group behavior a bit better.
........
r70867 | georg.brandl | 2009-03-31 14:10:35 -0500 (Tue, 31 Mar 2009) | 1 line
#1096310: document usage of sys.__std*__ a bit better.
........
r70868 | georg.brandl | 2009-03-31 14:12:17 -0500 (Tue, 31 Mar 2009) | 1 line
#5190: export make_option in __all__.
........
r70869 | georg.brandl | 2009-03-31 14:14:42 -0500 (Tue, 31 Mar 2009) | 1 line
Fix-up unwanted change.
........
r70870 | georg.brandl | 2009-03-31 14:26:24 -0500 (Tue, 31 Mar 2009) | 1 line
#4411: document mro() and __mro__. (I hope I got it right.)
........
r70871 | georg.brandl | 2009-03-31 14:30:56 -0500 (Tue, 31 Mar 2009) | 1 line
#5618: fix typo.
........
r70872 | r.david.murray | 2009-03-31 14:31:17 -0500 (Tue, 31 Mar 2009) | 3 lines
Delete out-of-date and little-known README from the test
directory by consensus of devs at pycon sprint.
........
r70883 | georg.brandl | 2009-03-31 15:41:08 -0500 (Tue, 31 Mar 2009) | 1 line
#1674032: return value of flag from Event.wait(). OKed by Guido.
........
r70885 | tarek.ziade | 2009-03-31 15:48:31 -0500 (Tue, 31 Mar 2009) | 1 line
using log.warn for sys.stderr
........
r70893 | georg.brandl | 2009-03-31 15:56:32 -0500 (Tue, 31 Mar 2009) | 1 line
#1530012: move TQS section before raw strings.
........
r70894 | benjamin.peterson | 2009-03-31 16:06:30 -0500 (Tue, 31 Mar 2009) | 1 line
take the usual lock precautions around _active_limbo_lock
........
r70896 | georg.brandl | 2009-03-31 16:15:33 -0500 (Tue, 31 Mar 2009) | 1 line
#5598: document DocFileSuite *args argument.
........
r70897 | benjamin.peterson | 2009-03-31 16:34:42 -0500 (Tue, 31 Mar 2009) | 1 line
fix Thread.ident when it is the main thread or a dummy thread #5632
........
r70903 | georg.brandl | 2009-03-31 16:45:18 -0500 (Tue, 31 Mar 2009) | 1 line
#1676135: remove trailing slashes from --prefix argument.
........
r70905 | georg.brandl | 2009-03-31 17:03:40 -0500 (Tue, 31 Mar 2009) | 1 line
#5563: more documentation for bdist_msi.
........
r70906 | georg.brandl | 2009-03-31 17:11:53 -0500 (Tue, 31 Mar 2009) | 1 line
#1651995: fix _convert_ref for non-ASCII characters.
........
r70907 | georg.brandl | 2009-03-31 17:18:19 -0500 (Tue, 31 Mar 2009) | 1 line
#3427: document correct return type for urlopen().info().
........
r70915 | georg.brandl | 2009-03-31 17:40:16 -0500 (Tue, 31 Mar 2009) | 1 line
#5018: remove confusing paragraph.
........
r70927 | georg.brandl | 2009-03-31 18:01:27 -0500 (Tue, 31 Mar 2009) | 1 line
Dont shout to users.
........
r70933 | georg.brandl | 2009-03-31 19:04:33 -0500 (Tue, 31 Mar 2009) | 2 lines
Issue #5635: Fix running test_sys with tracing enabled.
........
r70951 | georg.brandl | 2009-04-01 09:02:27 -0500 (Wed, 01 Apr 2009) | 1 line
Add Maksim, who worked on several issues at the sprint.
........
r70960 | jesse.noller | 2009-04-01 11:42:19 -0500 (Wed, 01 Apr 2009) | 1 line
Issue 3270: document Listener address restrictions on windows
........
r70962 | brett.cannon | 2009-04-01 12:07:16 -0500 (Wed, 01 Apr 2009) | 2 lines
Ron DuPlain was given commit privileges at PyCon 2009 to work on 3to2.
........
r70963 | georg.brandl | 2009-04-01 12:46:01 -0500 (Wed, 01 Apr 2009) | 1 line
#5655: fix docstring oversight.
........
r70964 | brett.cannon | 2009-04-01 12:52:13 -0500 (Wed, 01 Apr 2009) | 2 lines
Paul Kippes was given commit privileges to work on 3to2.
........
r70998 | georg.brandl | 2009-04-01 16:54:21 -0500 (Wed, 01 Apr 2009) | 1 line
In Pdb, stop assigning values to __builtin__._ which interferes with the one commonly installed by gettext.
........
r71001 | brett.cannon | 2009-04-01 18:01:12 -0500 (Wed, 01 Apr 2009) | 3 lines
Add my initials to Misc/developers.txt. Names are now sorted by number of
characters in the person's name.
........
r71006 | georg.brandl | 2009-04-01 18:32:17 -0500 (Wed, 01 Apr 2009) | 1 line
Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
........
r71008 | andrew.kuchling | 2009-04-01 19:02:14 -0500 (Wed, 01 Apr 2009) | 1 line
Typo fix
........
r71010 | benjamin.peterson | 2009-04-01 19:11:52 -0500 (Wed, 01 Apr 2009) | 1 line
fix markup
........
r71011 | benjamin.peterson | 2009-04-01 19:12:47 -0500 (Wed, 01 Apr 2009) | 1 line
this should be :noindex:
........
r71019 | georg.brandl | 2009-04-01 21:00:01 -0500 (Wed, 01 Apr 2009) | 1 line
Fix test_doctest, missed two assignments to curframe.
........
r71037 | r.david.murray | 2009-04-01 23:34:04 -0500 (Wed, 01 Apr 2009) | 6 lines
Clarify that datetime strftime does not produce leap seconds and datetime
strptime does not accept it in the strftime behavior section of the
datetime docs.
Closes issue 2568.
........
r71056 | georg.brandl | 2009-04-02 12:43:07 -0500 (Thu, 02 Apr 2009) | 2 lines
Actually the displayhook should print the repr.
........
r71094 | vinay.sajip | 2009-04-03 05:23:18 -0500 (Fri, 03 Apr 2009) | 1 line
Added warning about logging use from asynchronous signal handlers.
........
r71101 | andrew.kuchling | 2009-04-03 16:43:00 -0500 (Fri, 03 Apr 2009) | 1 line
Add some items
........
r71102 | andrew.kuchling | 2009-04-03 16:44:49 -0500 (Fri, 03 Apr 2009) | 1 line
Fix 'the the'; grammar fix
........
r71103 | andrew.kuchling | 2009-04-03 16:45:29 -0500 (Fri, 03 Apr 2009) | 1 line
Fix 'the the' duplication
........
r71106 | vinay.sajip | 2009-04-03 16:58:16 -0500 (Fri, 03 Apr 2009) | 1 line
Clarified warning about logging use from asynchronous signal handlers.
........
r71119 | raymond.hettinger | 2009-04-04 00:37:47 -0500 (Sat, 04 Apr 2009) | 1 line
Add helpful link.
........
r71123 | r.david.murray | 2009-04-04 01:39:56 -0500 (Sat, 04 Apr 2009) | 2 lines
Fix error in description of 'oct' (issue 5678).
........
r71149 | georg.brandl | 2009-04-04 08:42:39 -0500 (Sat, 04 Apr 2009) | 1 line
#5642: clarify map() compatibility to the builtin.
........
r71150 | georg.brandl | 2009-04-04 08:45:49 -0500 (Sat, 04 Apr 2009) | 1 line
#5601: clarify that webbrowser is not meant for file names.
........
r71203 | benjamin.peterson | 2009-04-04 18:46:34 -0500 (Sat, 04 Apr 2009) | 1 line
note how using iter* are unsafe while mutating and document iter(dict)
........
r71212 | georg.brandl | 2009-04-05 05:24:20 -0500 (Sun, 05 Apr 2009) | 1 line
#1742837: expand HTTP server docs, and fix SocketServer ones to document methods as methods, not functions.
........
r71214 | georg.brandl | 2009-04-05 05:29:57 -0500 (Sun, 05 Apr 2009) | 1 line
Normalize spelling of Mac OS X.
........
r71215 | georg.brandl | 2009-04-05 05:32:26 -0500 (Sun, 05 Apr 2009) | 1 line
Avoid sure signs of a diseased mind.
........
r71216 | georg.brandl | 2009-04-05 05:41:02 -0500 (Sun, 05 Apr 2009) | 1 line
#1718017: document the relation of os.path and the posixpath, ntpath etc. modules better.
........
r71217 | georg.brandl | 2009-04-05 05:48:47 -0500 (Sun, 05 Apr 2009) | 1 line
#1726172: dont raise an unexpected IndexError if a voidresp() call has an empty response.
........
r71221 | vinay.sajip | 2009-04-05 06:06:24 -0500 (Sun, 05 Apr 2009) | 1 line
Issue #5695: Moved logging.captureWarnings() call inside with statement in WarningsTest.test_warnings.
........
r71240 | georg.brandl | 2009-04-05 09:40:06 -0500 (Sun, 05 Apr 2009) | 1 line
#5370: doc update about unpickling objects with custom __getattr__ etc. methods.
........
2009-04-05 16:13:16 -03:00
|
|
|
|
|
|
|
|
2009-03-28 16:13:21 -03:00
|
|
|
.. method:: class.__subclasses__
|
|
|
|
|
2011-10-28 06:21:19 -03:00
|
|
|
Each class keeps a list of weak references to its immediate subclasses. This
|
|
|
|
method returns a list of all those references still alive.
|
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r70712 | benjamin.peterson | 2009-03-30 10:15:38 -0500 (Mon, 30 Mar 2009) | 1 line
don't rely on the order dict repr #5605
........
r70714 | brett.cannon | 2009-03-30 10:20:53 -0500 (Mon, 30 Mar 2009) | 1 line
Add an entry to developers.txt.
........
r70764 | martin.v.loewis | 2009-03-30 17:06:33 -0500 (Mon, 30 Mar 2009) | 2 lines
Add several VM developers.
........
r70765 | georg.brandl | 2009-03-30 17:09:34 -0500 (Mon, 30 Mar 2009) | 1 line
#5199: make warning about vars() assignment more visible.
........
r70769 | andrew.kuchling | 2009-03-30 17:29:53 -0500 (Mon, 30 Mar 2009) | 1 line
Remove comment
........
r70770 | andrew.kuchling | 2009-03-30 17:30:20 -0500 (Mon, 30 Mar 2009) | 1 line
Add several items and placeholders
........
r70771 | andrew.kuchling | 2009-03-30 17:31:11 -0500 (Mon, 30 Mar 2009) | 1 line
Many edits
........
r70773 | georg.brandl | 2009-03-30 17:43:00 -0500 (Mon, 30 Mar 2009) | 1 line
#5039: make it clear that the impl. note refers to CPython.
........
r70776 | andrew.kuchling | 2009-03-30 18:08:24 -0500 (Mon, 30 Mar 2009) | 1 line
typo fix
........
r70777 | andrew.kuchling | 2009-03-30 18:09:46 -0500 (Mon, 30 Mar 2009) | 1 line
Add more items
........
r70788 | andrew.kuchling | 2009-03-30 20:21:01 -0500 (Mon, 30 Mar 2009) | 1 line
Add various items
........
r70789 | georg.brandl | 2009-03-30 20:25:15 -0500 (Mon, 30 Mar 2009) | 1 line
Fix a wrong struct field assignment (docstring as closure).
........
r70824 | georg.brandl | 2009-03-31 10:43:20 -0500 (Tue, 31 Mar 2009) | 1 line
#5519: remove reference to Kodos, which seems dead.
........
r70828 | georg.brandl | 2009-03-31 10:50:16 -0500 (Tue, 31 Mar 2009) | 1 line
#5581: fget argument of abstractproperty is optional as well.
........
r70832 | georg.brandl | 2009-03-31 11:31:11 -0500 (Tue, 31 Mar 2009) | 1 line
#1386675: specify WindowsError as the exception, because it has a winerror attribute that EnvironmentError doesnt have.
........
r70836 | georg.brandl | 2009-03-31 11:50:25 -0500 (Tue, 31 Mar 2009) | 1 line
#5417: replace references to undocumented functions by ones to documented functions.
........
r70842 | georg.brandl | 2009-03-31 12:13:06 -0500 (Tue, 31 Mar 2009) | 1 line
#970783: document PyObject_Generic[GS]etAttr.
........
r70851 | georg.brandl | 2009-03-31 13:26:55 -0500 (Tue, 31 Mar 2009) | 1 line
#837577: note cryptic return value of spawn*e on invalid env dicts.
........
r70855 | georg.brandl | 2009-03-31 13:30:37 -0500 (Tue, 31 Mar 2009) | 1 line
#5245: note that PyRun_SimpleString doesnt return on SystemExit.
........
r70857 | georg.brandl | 2009-03-31 13:33:10 -0500 (Tue, 31 Mar 2009) | 1 line
#5227: note that Py_Main doesnt return on SystemExit.
........
r70866 | georg.brandl | 2009-03-31 14:06:57 -0500 (Tue, 31 Mar 2009) | 1 line
#4882: document named group behavior a bit better.
........
r70867 | georg.brandl | 2009-03-31 14:10:35 -0500 (Tue, 31 Mar 2009) | 1 line
#1096310: document usage of sys.__std*__ a bit better.
........
r70868 | georg.brandl | 2009-03-31 14:12:17 -0500 (Tue, 31 Mar 2009) | 1 line
#5190: export make_option in __all__.
........
r70869 | georg.brandl | 2009-03-31 14:14:42 -0500 (Tue, 31 Mar 2009) | 1 line
Fix-up unwanted change.
........
r70870 | georg.brandl | 2009-03-31 14:26:24 -0500 (Tue, 31 Mar 2009) | 1 line
#4411: document mro() and __mro__. (I hope I got it right.)
........
r70871 | georg.brandl | 2009-03-31 14:30:56 -0500 (Tue, 31 Mar 2009) | 1 line
#5618: fix typo.
........
r70872 | r.david.murray | 2009-03-31 14:31:17 -0500 (Tue, 31 Mar 2009) | 3 lines
Delete out-of-date and little-known README from the test
directory by consensus of devs at pycon sprint.
........
r70883 | georg.brandl | 2009-03-31 15:41:08 -0500 (Tue, 31 Mar 2009) | 1 line
#1674032: return value of flag from Event.wait(). OKed by Guido.
........
r70885 | tarek.ziade | 2009-03-31 15:48:31 -0500 (Tue, 31 Mar 2009) | 1 line
using log.warn for sys.stderr
........
r70893 | georg.brandl | 2009-03-31 15:56:32 -0500 (Tue, 31 Mar 2009) | 1 line
#1530012: move TQS section before raw strings.
........
r70894 | benjamin.peterson | 2009-03-31 16:06:30 -0500 (Tue, 31 Mar 2009) | 1 line
take the usual lock precautions around _active_limbo_lock
........
r70896 | georg.brandl | 2009-03-31 16:15:33 -0500 (Tue, 31 Mar 2009) | 1 line
#5598: document DocFileSuite *args argument.
........
r70897 | benjamin.peterson | 2009-03-31 16:34:42 -0500 (Tue, 31 Mar 2009) | 1 line
fix Thread.ident when it is the main thread or a dummy thread #5632
........
r70903 | georg.brandl | 2009-03-31 16:45:18 -0500 (Tue, 31 Mar 2009) | 1 line
#1676135: remove trailing slashes from --prefix argument.
........
r70905 | georg.brandl | 2009-03-31 17:03:40 -0500 (Tue, 31 Mar 2009) | 1 line
#5563: more documentation for bdist_msi.
........
r70906 | georg.brandl | 2009-03-31 17:11:53 -0500 (Tue, 31 Mar 2009) | 1 line
#1651995: fix _convert_ref for non-ASCII characters.
........
r70907 | georg.brandl | 2009-03-31 17:18:19 -0500 (Tue, 31 Mar 2009) | 1 line
#3427: document correct return type for urlopen().info().
........
r70915 | georg.brandl | 2009-03-31 17:40:16 -0500 (Tue, 31 Mar 2009) | 1 line
#5018: remove confusing paragraph.
........
r70927 | georg.brandl | 2009-03-31 18:01:27 -0500 (Tue, 31 Mar 2009) | 1 line
Dont shout to users.
........
r70933 | georg.brandl | 2009-03-31 19:04:33 -0500 (Tue, 31 Mar 2009) | 2 lines
Issue #5635: Fix running test_sys with tracing enabled.
........
r70951 | georg.brandl | 2009-04-01 09:02:27 -0500 (Wed, 01 Apr 2009) | 1 line
Add Maksim, who worked on several issues at the sprint.
........
r70960 | jesse.noller | 2009-04-01 11:42:19 -0500 (Wed, 01 Apr 2009) | 1 line
Issue 3270: document Listener address restrictions on windows
........
r70962 | brett.cannon | 2009-04-01 12:07:16 -0500 (Wed, 01 Apr 2009) | 2 lines
Ron DuPlain was given commit privileges at PyCon 2009 to work on 3to2.
........
r70963 | georg.brandl | 2009-04-01 12:46:01 -0500 (Wed, 01 Apr 2009) | 1 line
#5655: fix docstring oversight.
........
r70964 | brett.cannon | 2009-04-01 12:52:13 -0500 (Wed, 01 Apr 2009) | 2 lines
Paul Kippes was given commit privileges to work on 3to2.
........
r70998 | georg.brandl | 2009-04-01 16:54:21 -0500 (Wed, 01 Apr 2009) | 1 line
In Pdb, stop assigning values to __builtin__._ which interferes with the one commonly installed by gettext.
........
r71001 | brett.cannon | 2009-04-01 18:01:12 -0500 (Wed, 01 Apr 2009) | 3 lines
Add my initials to Misc/developers.txt. Names are now sorted by number of
characters in the person's name.
........
r71006 | georg.brandl | 2009-04-01 18:32:17 -0500 (Wed, 01 Apr 2009) | 1 line
Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
........
r71008 | andrew.kuchling | 2009-04-01 19:02:14 -0500 (Wed, 01 Apr 2009) | 1 line
Typo fix
........
r71010 | benjamin.peterson | 2009-04-01 19:11:52 -0500 (Wed, 01 Apr 2009) | 1 line
fix markup
........
r71011 | benjamin.peterson | 2009-04-01 19:12:47 -0500 (Wed, 01 Apr 2009) | 1 line
this should be :noindex:
........
r71019 | georg.brandl | 2009-04-01 21:00:01 -0500 (Wed, 01 Apr 2009) | 1 line
Fix test_doctest, missed two assignments to curframe.
........
r71037 | r.david.murray | 2009-04-01 23:34:04 -0500 (Wed, 01 Apr 2009) | 6 lines
Clarify that datetime strftime does not produce leap seconds and datetime
strptime does not accept it in the strftime behavior section of the
datetime docs.
Closes issue 2568.
........
r71056 | georg.brandl | 2009-04-02 12:43:07 -0500 (Thu, 02 Apr 2009) | 2 lines
Actually the displayhook should print the repr.
........
r71094 | vinay.sajip | 2009-04-03 05:23:18 -0500 (Fri, 03 Apr 2009) | 1 line
Added warning about logging use from asynchronous signal handlers.
........
r71101 | andrew.kuchling | 2009-04-03 16:43:00 -0500 (Fri, 03 Apr 2009) | 1 line
Add some items
........
r71102 | andrew.kuchling | 2009-04-03 16:44:49 -0500 (Fri, 03 Apr 2009) | 1 line
Fix 'the the'; grammar fix
........
r71103 | andrew.kuchling | 2009-04-03 16:45:29 -0500 (Fri, 03 Apr 2009) | 1 line
Fix 'the the' duplication
........
r71106 | vinay.sajip | 2009-04-03 16:58:16 -0500 (Fri, 03 Apr 2009) | 1 line
Clarified warning about logging use from asynchronous signal handlers.
........
r71119 | raymond.hettinger | 2009-04-04 00:37:47 -0500 (Sat, 04 Apr 2009) | 1 line
Add helpful link.
........
r71123 | r.david.murray | 2009-04-04 01:39:56 -0500 (Sat, 04 Apr 2009) | 2 lines
Fix error in description of 'oct' (issue 5678).
........
r71149 | georg.brandl | 2009-04-04 08:42:39 -0500 (Sat, 04 Apr 2009) | 1 line
#5642: clarify map() compatibility to the builtin.
........
r71150 | georg.brandl | 2009-04-04 08:45:49 -0500 (Sat, 04 Apr 2009) | 1 line
#5601: clarify that webbrowser is not meant for file names.
........
r71203 | benjamin.peterson | 2009-04-04 18:46:34 -0500 (Sat, 04 Apr 2009) | 1 line
note how using iter* are unsafe while mutating and document iter(dict)
........
r71212 | georg.brandl | 2009-04-05 05:24:20 -0500 (Sun, 05 Apr 2009) | 1 line
#1742837: expand HTTP server docs, and fix SocketServer ones to document methods as methods, not functions.
........
r71214 | georg.brandl | 2009-04-05 05:29:57 -0500 (Sun, 05 Apr 2009) | 1 line
Normalize spelling of Mac OS X.
........
r71215 | georg.brandl | 2009-04-05 05:32:26 -0500 (Sun, 05 Apr 2009) | 1 line
Avoid sure signs of a diseased mind.
........
r71216 | georg.brandl | 2009-04-05 05:41:02 -0500 (Sun, 05 Apr 2009) | 1 line
#1718017: document the relation of os.path and the posixpath, ntpath etc. modules better.
........
r71217 | georg.brandl | 2009-04-05 05:48:47 -0500 (Sun, 05 Apr 2009) | 1 line
#1726172: dont raise an unexpected IndexError if a voidresp() call has an empty response.
........
r71221 | vinay.sajip | 2009-04-05 06:06:24 -0500 (Sun, 05 Apr 2009) | 1 line
Issue #5695: Moved logging.captureWarnings() call inside with statement in WarningsTest.test_warnings.
........
r71240 | georg.brandl | 2009-04-05 09:40:06 -0500 (Sun, 05 Apr 2009) | 1 line
#5370: doc update about unpickling objects with custom __getattr__ etc. methods.
........
2009-04-05 16:13:16 -03:00
|
|
|
Example::
|
2009-03-28 16:13:21 -03:00
|
|
|
|
|
|
|
>>> int.__subclasses__()
|
2011-10-28 06:21:19 -03:00
|
|
|
[<class 'bool'>]
|
2009-03-28 16:13:21 -03:00
|
|
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. rubric:: Footnotes
|
|
|
|
|
2011-08-15 08:27:19 -03:00
|
|
|
.. [1] Additional information on these special methods may be found in the Python
|
2007-08-15 11:28:22 -03:00
|
|
|
Reference Manual (:ref:`customization`).
|
|
|
|
|
2011-08-15 08:27:19 -03:00
|
|
|
.. [2] As a consequence, the list ``[1, 2]`` is considered equal to ``[1.0, 2.0]``, and
|
2007-08-15 11:28:22 -03:00
|
|
|
similarly for tuples.
|
|
|
|
|
2011-08-15 08:27:19 -03:00
|
|
|
.. [3] They must have since the parser can't tell the type of the operands.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-08-15 08:27:19 -03:00
|
|
|
.. [4] Cased characters are those with general category property being one of
|
|
|
|
"Lu" (Letter, uppercase), "Ll" (Letter, lowercase), or "Lt" (Letter, titlecase).
|
|
|
|
|
|
|
|
.. [5] To format only a tuple you should therefore provide a singleton tuple whose only
|
2007-08-15 11:28:22 -03:00
|
|
|
element is the tuple to be formatted.
|