2008-03-25 04:21:32 -03:00
|
|
|
.. XXX document all delegations to __special__ methods
|
2007-08-15 11:28:22 -03:00
|
|
|
.. _built-in-funcs:
|
|
|
|
|
|
|
|
Built-in Functions
|
|
|
|
==================
|
|
|
|
|
2008-05-05 18:05:32 -03:00
|
|
|
The Python interpreter has a number of functions and types built into it that
|
|
|
|
are always available. They are listed here in alphabetical order.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2020-07-09 06:38:41 -03:00
|
|
|
+---------------------------------------------------------------------------------------------------+
|
|
|
|
| Built-in Functions |
|
|
|
|
+=========================+=======================+=======================+=========================+
|
|
|
|
| | **A** | | **E** | | **L** | | **R** |
|
|
|
|
| | :func:`abs` | | :func:`enumerate` | | :func:`len` | | |func-range|_ |
|
2021-03-23 19:47:21 -03:00
|
|
|
| | :func:`aiter` | | :func:`eval` | | |func-list|_ | | :func:`repr` |
|
|
|
|
| | :func:`all` | | :func:`exec` | | :func:`locals` | | :func:`reversed` |
|
|
|
|
| | :func:`any` | | | | | | :func:`round` |
|
|
|
|
| | :func:`anext` | | **F** | | **M** | | |
|
|
|
|
| | :func:`ascii` | | :func:`filter` | | :func:`map` | | **S** |
|
|
|
|
| | | | :func:`float` | | :func:`max` | | |func-set|_ |
|
|
|
|
| | **B** | | :func:`format` | | |func-memoryview|_ | | :func:`setattr` |
|
|
|
|
| | :func:`bin` | | |func-frozenset|_ | | :func:`min` | | :func:`slice` |
|
|
|
|
| | :func:`bool` | | | | | | :func:`sorted` |
|
|
|
|
| | :func:`breakpoint` | | **G** | | **N** | | :func:`staticmethod` |
|
|
|
|
| | |func-bytearray|_ | | :func:`getattr` | | :func:`next` | | |func-str|_ |
|
|
|
|
| | |func-bytes|_ | | :func:`globals` | | | | :func:`sum` |
|
|
|
|
| | | | | | **O** | | :func:`super` |
|
|
|
|
| | **C** | | **H** | | :func:`object` | | |
|
|
|
|
| | :func:`callable` | | :func:`hasattr` | | :func:`oct` | | **T** |
|
|
|
|
| | :func:`chr` | | :func:`hash` | | :func:`open` | | |func-tuple|_ |
|
|
|
|
| | :func:`classmethod` | | :func:`help` | | :func:`ord` | | :func:`type` |
|
|
|
|
| | :func:`compile` | | :func:`hex` | | | | |
|
|
|
|
| | :func:`complex` | | | | **P** | | **V** |
|
|
|
|
| | | | **I** | | :func:`pow` | | :func:`vars` |
|
|
|
|
| | **D** | | :func:`id` | | :func:`print` | | |
|
|
|
|
| | :func:`delattr` | | :func:`input` | | :func:`property` | | **Z** |
|
|
|
|
| | |func-dict|_ | | :func:`int` | | | | :func:`zip` |
|
|
|
|
| | :func:`dir` | | :func:`isinstance` | | | | |
|
|
|
|
| | :func:`divmod` | | :func:`issubclass` | | | | **_** |
|
2020-07-09 06:38:41 -03:00
|
|
|
| | | | :func:`iter` | | | | :func:`__import__` |
|
|
|
|
+-------------------------+-----------------------+-----------------------+-------------------------+
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-09-01 18:08:55 -03:00
|
|
|
.. using :func:`dict` would create a link to another page, so local targets are
|
|
|
|
used, with replacement texts to make the output in the table consistent
|
|
|
|
|
|
|
|
.. |func-dict| replace:: ``dict()``
|
|
|
|
.. |func-frozenset| replace:: ``frozenset()``
|
|
|
|
.. |func-memoryview| replace:: ``memoryview()``
|
|
|
|
.. |func-set| replace:: ``set()``
|
2012-08-21 04:42:52 -03:00
|
|
|
.. |func-list| replace:: ``list()``
|
2012-11-28 05:38:40 -04:00
|
|
|
.. |func-str| replace:: ``str()``
|
2012-08-21 04:42:52 -03:00
|
|
|
.. |func-tuple| replace:: ``tuple()``
|
|
|
|
.. |func-range| replace:: ``range()``
|
2017-04-26 02:47:01 -03:00
|
|
|
.. |func-bytearray| replace:: ``bytearray()``
|
|
|
|
.. |func-bytes| replace:: ``bytes()``
|
2011-09-01 18:08:55 -03:00
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: abs(x)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2007-11-29 13:24:34 -04:00
|
|
|
Return the absolute value of a number. The argument may be an
|
2020-05-29 08:35:34 -03:00
|
|
|
integer, a floating point number, or an object implementing :meth:`__abs__`.
|
|
|
|
If the argument is a complex number, its magnitude is returned.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: aiter(async_iterable)
|
2021-03-23 19:47:21 -03:00
|
|
|
|
|
|
|
Return an :term:`asynchronous iterator` for an :term:`asynchronous iterable`.
|
|
|
|
Equivalent to calling ``x.__aiter__()``.
|
|
|
|
|
|
|
|
Note: Unlike :func:`iter`, :func:`aiter` has no 2-argument variant.
|
|
|
|
|
2021-03-23 20:57:03 -03:00
|
|
|
.. versionadded:: 3.10
|
2021-03-23 19:47:21 -03:00
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: all(iterable)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2013-11-29 06:17:13 -04:00
|
|
|
Return ``True`` if all elements of the *iterable* are true (or if the iterable
|
2009-04-27 13:49:41 -03:00
|
|
|
is empty). Equivalent to::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
def all(iterable):
|
|
|
|
for element in iterable:
|
|
|
|
if not element:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. awaitablefunction:: anext(async_iterator)
|
|
|
|
anext(async_iterator, default)
|
2021-03-23 19:47:21 -03:00
|
|
|
|
|
|
|
When awaited, return the next item from the given :term:`asynchronous
|
|
|
|
iterator`, or *default* if given and the iterator is exhausted.
|
|
|
|
|
|
|
|
This is the async variant of the :func:`next` builtin, and behaves
|
|
|
|
similarly.
|
|
|
|
|
|
|
|
This calls the :meth:`~object.__anext__` method of *async_iterator*,
|
|
|
|
returning an :term:`awaitable`. Awaiting this returns the next value of the
|
|
|
|
iterator. If *default* is given, it is returned if the iterator is exhausted,
|
|
|
|
otherwise :exc:`StopAsyncIteration` is raised.
|
|
|
|
|
2021-03-23 20:57:03 -03:00
|
|
|
.. versionadded:: 3.10
|
2021-03-23 19:47:21 -03:00
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: any(iterable)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2013-11-29 06:17:13 -04:00
|
|
|
Return ``True`` if any element of the *iterable* is true. If the iterable
|
|
|
|
is empty, return ``False``. Equivalent to::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
def any(iterable):
|
|
|
|
for element in iterable:
|
|
|
|
if element:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: ascii(object)
|
2008-06-11 15:37:52 -03:00
|
|
|
|
|
|
|
As :func:`repr`, return a string containing a printable representation of an
|
|
|
|
object, but escape the non-ASCII characters in the string returned by
|
2021-07-19 13:02:23 -03:00
|
|
|
:func:`repr` using ``\x``, ``\u``, or ``\U`` escapes. This generates a string
|
2008-06-11 15:37:52 -03:00
|
|
|
similar to that returned by :func:`repr` in Python 2.
|
|
|
|
|
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: bin(x)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-07-06 16:30:58 -03:00
|
|
|
Convert an integer number to a binary string prefixed with "0b". The result
|
|
|
|
is a valid Python expression. If *x* is not a Python :class:`int` object, it
|
2023-06-30 11:27:09 -03:00
|
|
|
has to define an :meth:`~object.__index__` method that returns an integer. Some
|
2017-07-06 16:30:58 -03:00
|
|
|
examples:
|
|
|
|
|
|
|
|
>>> bin(3)
|
|
|
|
'0b11'
|
|
|
|
>>> bin(-10)
|
|
|
|
'-0b1010'
|
|
|
|
|
2021-07-19 13:02:23 -03:00
|
|
|
If the prefix "0b" is desired or not, you can use either of the following ways.
|
2017-07-06 16:30:58 -03:00
|
|
|
|
|
|
|
>>> format(14, '#b'), format(14, 'b')
|
|
|
|
('0b1110', '1110')
|
|
|
|
>>> f'{14:#b}', f'{14:b}'
|
|
|
|
('0b1110', '1110')
|
|
|
|
|
2018-06-29 06:57:10 -03:00
|
|
|
See also :func:`format` for more information.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. class:: bool(x=False)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2014-10-06 08:54:36 -03:00
|
|
|
Return a Boolean value, i.e. one of ``True`` or ``False``. *x* is converted
|
|
|
|
using the standard :ref:`truth testing procedure <truth>`. If *x* is false
|
2021-07-19 13:02:23 -03:00
|
|
|
or omitted, this returns ``False``; otherwise, it returns ``True``. The
|
2014-10-06 08:54:36 -03:00
|
|
|
:class:`bool` class is a subclass of :class:`int` (see :ref:`typesnumeric`).
|
|
|
|
It cannot be subclassed further. Its only instances are ``False`` and
|
2023-05-03 04:00:42 -03:00
|
|
|
``True`` (see :ref:`typebool`).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. index:: pair: Boolean; type
|
|
|
|
|
2018-08-27 07:45:26 -03:00
|
|
|
.. versionchanged:: 3.7
|
|
|
|
*x* is now a positional-only parameter.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-10-05 13:11:18 -03:00
|
|
|
.. function:: breakpoint(*args, **kws)
|
|
|
|
|
|
|
|
This function drops you into the debugger at the call site. Specifically,
|
|
|
|
it calls :func:`sys.breakpointhook`, passing ``args`` and ``kws`` straight
|
|
|
|
through. By default, ``sys.breakpointhook()`` calls
|
|
|
|
:func:`pdb.set_trace()` expecting no arguments. In this case, it is
|
|
|
|
purely a convenience function so you don't have to explicitly import
|
|
|
|
:mod:`pdb` or type as much code to enter the debugger. However,
|
|
|
|
:func:`sys.breakpointhook` can be set to some other function and
|
|
|
|
:func:`breakpoint` will automatically call that, allowing you to drop into
|
|
|
|
the debugger of choice.
|
2022-08-25 22:43:02 -03:00
|
|
|
If :func:`sys.breakpointhook` is not accessible, this function will
|
2022-08-24 11:03:36 -03:00
|
|
|
raise :exc:`RuntimeError`.
|
2017-10-05 13:11:18 -03:00
|
|
|
|
2023-05-13 04:12:03 -03:00
|
|
|
By default, the behavior of :func:`breakpoint` can be changed with
|
|
|
|
the :envvar:`PYTHONBREAKPOINT` environment variable.
|
|
|
|
See :func:`sys.breakpointhook` for usage details.
|
|
|
|
|
|
|
|
Note that this is not guaranteed if :func:`sys.breakpointhook`
|
|
|
|
has been replaced.
|
|
|
|
|
2019-06-27 14:47:59 -03:00
|
|
|
.. audit-event:: builtins.breakpoint breakpointhook breakpoint
|
2019-06-24 12:42:54 -03:00
|
|
|
|
2017-10-05 13:11:18 -03:00
|
|
|
.. versionadded:: 3.7
|
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
.. _func-bytearray:
|
2022-10-15 07:19:35 -03:00
|
|
|
.. class:: bytearray(source=b'')
|
|
|
|
bytearray(source, encoding)
|
|
|
|
bytearray(source, encoding, errors)
|
2017-04-26 02:47:01 -03:00
|
|
|
:noindex:
|
2007-08-31 13:33:38 -03:00
|
|
|
|
2014-10-06 08:54:36 -03:00
|
|
|
Return a new array of bytes. The :class:`bytearray` class is a mutable
|
2007-11-22 07:00:28 -04:00
|
|
|
sequence of integers in the range 0 <= x < 256. It has most of the usual
|
|
|
|
methods of mutable sequences, described in :ref:`typesseq-mutable`, as well
|
2010-11-20 15:36:05 -04:00
|
|
|
as most methods that the :class:`bytes` type has, see :ref:`bytes-methods`.
|
2007-08-31 13:33:38 -03:00
|
|
|
|
2009-05-17 10:00:36 -03:00
|
|
|
The optional *source* parameter can be used to initialize the array in a few
|
2007-08-31 13:33:38 -03:00
|
|
|
different ways:
|
|
|
|
|
|
|
|
* If it is a *string*, you must also give the *encoding* (and optionally,
|
2008-02-01 07:56:49 -04:00
|
|
|
*errors*) parameters; :func:`bytearray` then converts the string to
|
2007-11-06 17:34:58 -04:00
|
|
|
bytes using :meth:`str.encode`.
|
2007-08-31 13:33:38 -03:00
|
|
|
|
|
|
|
* If it is an *integer*, the array will have that size and will be
|
|
|
|
initialized with null bytes.
|
|
|
|
|
2020-10-26 02:26:34 -03:00
|
|
|
* If it is an object conforming to the :ref:`buffer interface <bufferobjects>`,
|
|
|
|
a read-only buffer of the object will be used to initialize the bytes array.
|
2007-08-31 13:33:38 -03:00
|
|
|
|
2007-11-06 17:34:58 -04:00
|
|
|
* If it is an *iterable*, it must be an iterable of integers in the range
|
|
|
|
``0 <= x < 256``, which are used as the initial contents of the array.
|
2007-08-31 13:33:38 -03:00
|
|
|
|
|
|
|
Without an argument, an array of size 0 is created.
|
|
|
|
|
2012-10-13 00:28:26 -03:00
|
|
|
See also :ref:`binaryseq` and :ref:`typebytearray`.
|
|
|
|
|
2007-08-31 13:33:38 -03:00
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
.. _func-bytes:
|
2022-10-15 07:19:35 -03:00
|
|
|
.. class:: bytes(source=b'')
|
|
|
|
bytes(source, encoding)
|
|
|
|
bytes(source, encoding, errors)
|
2017-04-26 02:47:01 -03:00
|
|
|
:noindex:
|
2007-11-06 17:34:58 -04:00
|
|
|
|
2021-07-19 13:02:23 -03:00
|
|
|
Return a new "bytes" object which is an immutable sequence of integers in
|
2007-11-06 17:34:58 -04:00
|
|
|
the range ``0 <= x < 256``. :class:`bytes` is an immutable version of
|
2007-11-22 07:00:28 -04:00
|
|
|
:class:`bytearray` -- it has the same non-mutating methods and the same
|
|
|
|
indexing and slicing behavior.
|
2009-01-03 17:18:54 -04:00
|
|
|
|
2009-04-29 03:37:12 -03:00
|
|
|
Accordingly, constructor arguments are interpreted as for :func:`bytearray`.
|
2007-11-06 17:34:58 -04:00
|
|
|
|
|
|
|
Bytes objects can also be created with literals, see :ref:`strings`.
|
|
|
|
|
2012-10-13 00:28:26 -03:00
|
|
|
See also :ref:`binaryseq`, :ref:`typebytes`, and :ref:`bytes-methods`.
|
|
|
|
|
2007-11-06 17:34:58 -04:00
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: callable(object)
|
2010-11-27 18:00:11 -04:00
|
|
|
|
|
|
|
Return :const:`True` if the *object* argument appears callable,
|
2019-11-12 10:57:03 -04:00
|
|
|
:const:`False` if not. If this returns ``True``, it is still possible that a
|
|
|
|
call fails, but if it is ``False``, calling *object* will never succeed.
|
2010-11-27 18:00:11 -04:00
|
|
|
Note that classes are callable (calling a class returns a new instance);
|
|
|
|
instances are callable if their class has a :meth:`__call__` method.
|
|
|
|
|
|
|
|
.. versionadded:: 3.2
|
|
|
|
This function was first removed in Python 3.0 and then brought back
|
|
|
|
in Python 3.2.
|
|
|
|
|
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: chr(i)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2015-01-14 03:26:30 -04:00
|
|
|
Return the string representing a character whose Unicode code point is the
|
2014-08-17 01:07:53 -03:00
|
|
|
integer *i*. For example, ``chr(97)`` returns the string ``'a'``, while
|
2016-03-23 14:36:52 -03:00
|
|
|
``chr(8364)`` returns the string ``'€'``. This is the inverse of :func:`ord`.
|
2014-08-17 01:07:53 -03:00
|
|
|
|
|
|
|
The valid range for the argument is from 0 through 1,114,111 (0x10FFFF in
|
|
|
|
base 16). :exc:`ValueError` will be raised if *i* is outside that range.
|
2010-11-18 14:50:13 -04:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-10-12 11:39:43 -03:00
|
|
|
.. decorator:: classmethod
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-10-12 11:39:43 -03:00
|
|
|
Transform a method into a class method.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2021-07-19 13:02:23 -03:00
|
|
|
A class method receives the class as an implicit first argument, just like an
|
2007-08-15 11:28:22 -03:00
|
|
|
instance method receives the instance. To declare a class method, use this
|
|
|
|
idiom::
|
|
|
|
|
|
|
|
class C:
|
|
|
|
@classmethod
|
2022-01-26 06:06:10 -04:00
|
|
|
def f(cls, arg1, arg2): ...
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2019-03-25 19:53:43 -03:00
|
|
|
The ``@classmethod`` form is a function :term:`decorator` -- see
|
|
|
|
:ref:`function` for details.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2019-03-25 19:53:43 -03:00
|
|
|
A class method can be called either on the class (such as ``C.f()``) or on an instance (such
|
2007-08-15 11:28:22 -03:00
|
|
|
as ``C().f()``). The instance is ignored except for its class. If a class
|
|
|
|
method is called for a derived class, the derived class object is passed as the
|
|
|
|
implied first argument.
|
|
|
|
|
|
|
|
Class methods are different than C++ or Java static methods. If you want those,
|
2019-08-24 19:37:25 -03:00
|
|
|
see :func:`staticmethod` in this section.
|
2019-03-25 19:53:43 -03:00
|
|
|
For more information on class methods, see :ref:`types`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2019-08-24 19:37:25 -03:00
|
|
|
.. versionchanged:: 3.9
|
|
|
|
Class methods can now wrap other :term:`descriptors <descriptor>` such as
|
|
|
|
:func:`property`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2021-04-09 12:51:22 -03:00
|
|
|
.. versionchanged:: 3.10
|
|
|
|
Class methods now inherit the method attributes (``__module__``,
|
|
|
|
``__name__``, ``__qualname__``, ``__doc__`` and ``__annotations__``) and
|
|
|
|
have a new ``__wrapped__`` attribute.
|
|
|
|
|
2022-05-06 04:57:53 -03:00
|
|
|
.. versionchanged:: 3.11
|
|
|
|
Class methods can no longer wrap other :term:`descriptors <descriptor>` such as
|
|
|
|
:func:`property`.
|
|
|
|
|
|
|
|
|
2010-12-04 06:26:46 -04:00
|
|
|
.. function:: compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-11-08 13:05:00 -04:00
|
|
|
Compile the *source* into a code or AST object. Code objects can be executed
|
2013-12-06 21:12:39 -04:00
|
|
|
by :func:`exec` or :func:`eval`. *source* can either be a normal string, a
|
|
|
|
byte string, or an AST object. Refer to the :mod:`ast` module documentation
|
|
|
|
for information on how to work with AST objects.
|
2008-11-08 13:05:00 -04:00
|
|
|
|
|
|
|
The *filename* argument should give the file from which the code was read;
|
|
|
|
pass some recognizable value if it wasn't read from a file (``'<string>'`` is
|
|
|
|
commonly used).
|
|
|
|
|
|
|
|
The *mode* argument specifies what kind of code must be compiled; it can be
|
|
|
|
``'exec'`` if *source* consists of a sequence of statements, ``'eval'`` if it
|
|
|
|
consists of a single expression, or ``'single'`` if it consists of a single
|
|
|
|
interactive statement (in the latter case, expression statements that
|
2009-06-25 14:37:57 -03:00
|
|
|
evaluate to something other than ``None`` will be printed).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2020-10-29 17:48:21 -03:00
|
|
|
The optional arguments *flags* and *dont_inherit* control which
|
2020-10-18 22:14:11 -03:00
|
|
|
:ref:`compiler options <ast-compiler-flags>` should be activated
|
|
|
|
and which :ref:`future features <future>` should be allowed. If neither
|
|
|
|
is present (or both are zero) the code is compiled with the same flags that
|
|
|
|
affect the code that is calling :func:`compile`. If the *flags*
|
|
|
|
argument is given and *dont_inherit* is not (or is zero) then the compiler
|
|
|
|
options and the future statements specified by the *flags* argument are used
|
|
|
|
in addition to those that would be used anyway. If *dont_inherit* is a
|
|
|
|
non-zero integer then the *flags* argument is it -- the flags (future
|
|
|
|
features and compiler options) in the surrounding code are ignored.
|
|
|
|
|
|
|
|
Compiler options and future statements are specified by bits which can be
|
|
|
|
bitwise ORed together to specify multiple options. The bitfield required to
|
|
|
|
specify a given future feature can be found as the
|
|
|
|
:attr:`~__future__._Feature.compiler_flag` attribute on the
|
|
|
|
:class:`~__future__._Feature` instance in the :mod:`__future__` module.
|
|
|
|
:ref:`Compiler flags <ast-compiler-flags>` can be found in :mod:`ast`
|
|
|
|
module, with ``PyCF_`` prefix.
|
2019-05-21 17:12:03 -03:00
|
|
|
|
2010-12-04 06:26:46 -04:00
|
|
|
The argument *optimize* specifies the optimization level of the compiler; the
|
|
|
|
default value of ``-1`` selects the optimization level of the interpreter as
|
|
|
|
given by :option:`-O` options. Explicit levels are ``0`` (no optimization;
|
|
|
|
``__debug__`` is true), ``1`` (asserts are removed, ``__debug__`` is false)
|
|
|
|
or ``2`` (docstrings are removed too).
|
|
|
|
|
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
|
|
|
This function raises :exc:`SyntaxError` if the compiled source is invalid,
|
2016-02-21 16:00:12 -04:00
|
|
|
and :exc:`ValueError` if the source contains null bytes.
|
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
|
|
|
|
2014-10-31 05:41:46 -03:00
|
|
|
If you want to parse Python code into its AST representation, see
|
|
|
|
:func:`ast.parse`.
|
|
|
|
|
2019-06-27 14:47:59 -03:00
|
|
|
.. audit-event:: compile source,filename compile
|
2019-05-23 12:45:22 -03:00
|
|
|
|
2019-06-24 12:42:54 -03:00
|
|
|
Raises an :ref:`auditing event <auditing>` ``compile`` with arguments
|
2019-05-23 12:45:22 -03:00
|
|
|
``source`` and ``filename``. This event may also be raised by implicit
|
|
|
|
compilation.
|
|
|
|
|
2008-11-08 13:05:00 -04:00
|
|
|
.. note::
|
|
|
|
|
Merged revisions 76259,76326,76376-76377,76430,76471,76517 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r76259 | georg.brandl | 2009-11-14 05:50:51 -0600 (Sat, 14 Nov 2009) | 1 line
Fix terminology.
................
r76326 | georg.brandl | 2009-11-16 10:44:05 -0600 (Mon, 16 Nov 2009) | 1 line
#7302: fix link.
................
r76376 | georg.brandl | 2009-11-18 13:39:14 -0600 (Wed, 18 Nov 2009) | 1 line
upcase Python
................
r76377 | georg.brandl | 2009-11-18 14:05:15 -0600 (Wed, 18 Nov 2009) | 1 line
Fix markup.
................
r76430 | r.david.murray | 2009-11-20 07:29:43 -0600 (Fri, 20 Nov 2009) | 2 lines
Issue 7363: fix indentation in socketserver udpserver example.
................
r76471 | georg.brandl | 2009-11-23 13:53:19 -0600 (Mon, 23 Nov 2009) | 1 line
#7345: fix arguments of formatyear().
................
r76517 | benjamin.peterson | 2009-11-25 12:16:46 -0600 (Wed, 25 Nov 2009) | 29 lines
Merged revisions 76160-76161,76250,76252,76447,76506 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r76160 | benjamin.peterson | 2009-11-08 18:53:48 -0600 (Sun, 08 Nov 2009) | 1 line
undeprecate the -p option; it's useful for converting python3 sources
........
r76161 | benjamin.peterson | 2009-11-08 19:05:37 -0600 (Sun, 08 Nov 2009) | 1 line
simplify condition
........
r76250 | benjamin.peterson | 2009-11-13 16:56:48 -0600 (Fri, 13 Nov 2009) | 1 line
fix handling of a utf-8 bom #7313
........
r76252 | benjamin.peterson | 2009-11-13 16:58:36 -0600 (Fri, 13 Nov 2009) | 1 line
remove pdb turd
........
r76447 | benjamin.peterson | 2009-11-22 18:17:40 -0600 (Sun, 22 Nov 2009) | 1 line
#7375 fix nested transformations in fix_urllib
........
r76506 | benjamin.peterson | 2009-11-24 18:34:31 -0600 (Tue, 24 Nov 2009) | 1 line
use generator expressions in any()
........
................
2009-11-25 14:34:42 -04:00
|
|
|
When compiling a string with multi-line code in ``'single'`` or
|
2009-11-12 20:17:59 -04:00
|
|
|
``'eval'`` mode, input must be terminated by at least one newline
|
|
|
|
character. This is to facilitate detection of incomplete and complete
|
|
|
|
statements in the :mod:`code` module.
|
|
|
|
|
2018-03-09 17:13:32 -04:00
|
|
|
.. warning::
|
|
|
|
|
|
|
|
It is possible to crash the Python interpreter with a
|
|
|
|
sufficiently large/complex string when compiling to an AST
|
|
|
|
object due to stack depth limitations in Python's AST compiler.
|
|
|
|
|
2009-11-12 20:17:59 -04:00
|
|
|
.. versionchanged:: 3.2
|
2021-07-19 13:02:23 -03:00
|
|
|
Allowed use of Windows and Mac newlines. Also, input in ``'exec'`` mode
|
2010-12-04 06:26:46 -04:00
|
|
|
does not have to end in a newline anymore. Added the *optimize* parameter.
|
2008-11-08 13:05:00 -04:00
|
|
|
|
2016-02-21 16:00:12 -04:00
|
|
|
.. versionchanged:: 3.5
|
|
|
|
Previously, :exc:`TypeError` was raised when null bytes were encountered
|
|
|
|
in *source*.
|
|
|
|
|
2019-05-21 17:12:03 -03:00
|
|
|
.. versionadded:: 3.8
|
|
|
|
``ast.PyCF_ALLOW_TOP_LEVEL_AWAIT`` can now be passed in flags to enable
|
|
|
|
support for top-level ``await``, ``async for``, and ``async with``.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-10-15 07:19:35 -03:00
|
|
|
.. class:: complex(real=0, imag=0)
|
2022-11-19 06:25:45 -04:00
|
|
|
complex(string)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2015-05-23 17:16:28 -03:00
|
|
|
Return a complex number with the value *real* + *imag*\*1j or convert a string
|
2014-10-06 08:54:36 -03:00
|
|
|
or number to a complex number. If the first parameter is a string, it will
|
|
|
|
be interpreted as a complex number and the function must be called without a
|
|
|
|
second parameter. The second parameter can never be a string. Each argument
|
|
|
|
may be any numeric type (including complex). If *imag* is omitted, it
|
|
|
|
defaults to zero and the constructor serves as a numeric conversion like
|
|
|
|
:class:`int` and :class:`float`. If both arguments are omitted, returns
|
|
|
|
``0j``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2019-06-01 18:05:48 -03:00
|
|
|
For a general Python object ``x``, ``complex(x)`` delegates to
|
2023-06-30 11:27:09 -03:00
|
|
|
``x.__complex__()``. If :meth:`~object.__complex__` is not defined then it falls back
|
|
|
|
to :meth:`~object.__float__`. If :meth:`!__float__` is not defined then it falls back
|
|
|
|
to :meth:`~object.__index__`.
|
2019-06-01 18:05:48 -03:00
|
|
|
|
2012-03-10 12:09:35 -04:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
When converting from a string, the string must not contain whitespace
|
|
|
|
around the central ``+`` or ``-`` operator. For example,
|
|
|
|
``complex('1+2j')`` is fine, but ``complex('1 + 2j')`` raises
|
|
|
|
:exc:`ValueError`.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
The complex type is described in :ref:`typesnumeric`.
|
|
|
|
|
2016-09-09 18:57:09 -03:00
|
|
|
.. versionchanged:: 3.6
|
|
|
|
Grouping digits with underscores as in code literals is allowed.
|
|
|
|
|
2019-06-01 18:05:48 -03:00
|
|
|
.. versionchanged:: 3.8
|
2023-06-30 11:27:09 -03:00
|
|
|
Falls back to :meth:`~object.__index__` if :meth:`~object.__complex__` and
|
|
|
|
:meth:`~object.__float__` are not defined.
|
2019-06-01 18:05:48 -03:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: delattr(object, name)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
This is a relative of :func:`setattr`. The arguments are an object and a
|
|
|
|
string. The string must be the name of one of the object's attributes. The
|
|
|
|
function deletes the named attribute, provided the object allows it. For
|
|
|
|
example, ``delattr(x, 'foobar')`` is equivalent to ``del x.foobar``.
|
2022-09-29 20:02:27 -03:00
|
|
|
*name* need not be a Python identifier (see :func:`setattr`).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2011-09-01 18:08:55 -03:00
|
|
|
.. _func-dict:
|
2014-10-06 08:54:36 -03:00
|
|
|
.. class:: dict(**kwarg)
|
2022-11-19 06:25:45 -04:00
|
|
|
dict(mapping, **kwarg)
|
|
|
|
dict(iterable, **kwarg)
|
2007-08-15 11:28:22 -03:00
|
|
|
:noindex:
|
|
|
|
|
2012-10-13 07:22:33 -03:00
|
|
|
Create a new dictionary. The :class:`dict` object is the dictionary class.
|
2014-10-06 08:54:36 -03:00
|
|
|
See :class:`dict` and :ref:`typesmapping` for documentation about this class.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-10-13 07:22:33 -03:00
|
|
|
For other containers see the built-in :class:`list`, :class:`set`, and
|
|
|
|
:class:`tuple` classes, as well as the :mod:`collections` module.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2022-10-15 07:19:35 -03:00
|
|
|
.. function:: dir()
|
2022-11-19 06:25:45 -04:00
|
|
|
dir(object)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Without arguments, return the list of names in the current local scope. With an
|
|
|
|
argument, attempt to return a list of valid attributes for that object.
|
|
|
|
|
|
|
|
If the object has a method named :meth:`__dir__`, this method will be called and
|
|
|
|
must return the list of attributes. This allows objects that implement a custom
|
|
|
|
:func:`__getattr__` or :func:`__getattribute__` function to customize the way
|
|
|
|
:func:`dir` reports their attributes.
|
|
|
|
|
|
|
|
If the object does not provide :meth:`__dir__`, the function tries its best to
|
2016-06-18 00:57:31 -03:00
|
|
|
gather information from the object's :attr:`~object.__dict__` attribute, if defined, and
|
2021-07-19 13:02:23 -03:00
|
|
|
from its type object. The resulting list is not necessarily complete and may
|
2007-08-15 11:28:22 -03:00
|
|
|
be inaccurate when the object has a custom :func:`__getattr__`.
|
|
|
|
|
|
|
|
The default :func:`dir` mechanism behaves differently with different types of
|
|
|
|
objects, as it attempts to produce the most relevant, rather than complete,
|
|
|
|
information:
|
|
|
|
|
|
|
|
* If the object is a module object, the list contains the names of the module's
|
|
|
|
attributes.
|
|
|
|
|
|
|
|
* If the object is a type or class object, the list contains the names of its
|
|
|
|
attributes, and recursively of the attributes of its bases.
|
|
|
|
|
|
|
|
* Otherwise, the list contains the object's attributes' names, the names of its
|
|
|
|
class's attributes, and recursively of the attributes of its class's base
|
|
|
|
classes.
|
|
|
|
|
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
|
|
|
The resulting list is sorted alphabetically. For example:
|
|
|
|
|
|
|
|
>>> import struct
|
2017-04-27 09:23:34 -03:00
|
|
|
>>> dir() # show the names in the module namespace # doctest: +SKIP
|
2012-08-12 09:16:42 -03:00
|
|
|
['__builtins__', '__name__', 'struct']
|
|
|
|
>>> dir(struct) # show the names in the struct module # doctest: +SKIP
|
|
|
|
['Struct', '__all__', '__builtins__', '__cached__', '__doc__', '__file__',
|
|
|
|
'__initializing__', '__loader__', '__name__', '__package__',
|
|
|
|
'_clearcache', 'calcsize', 'error', 'pack', 'pack_into',
|
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
|
|
|
'unpack', 'unpack_from']
|
2013-03-11 04:30:21 -03:00
|
|
|
>>> class Shape:
|
2012-08-12 09:16:42 -03:00
|
|
|
... def __dir__(self):
|
|
|
|
... return ['area', 'perimeter', 'location']
|
2022-12-08 23:31:19 -04:00
|
|
|
...
|
2011-06-01 20:17:23 -03:00
|
|
|
>>> s = Shape()
|
|
|
|
>>> dir(s)
|
2012-08-12 09:16:42 -03:00
|
|
|
['area', 'location', 'perimeter']
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
Because :func:`dir` is supplied primarily as a convenience for use at an
|
2009-05-17 10:00:36 -03:00
|
|
|
interactive prompt, it tries to supply an interesting set of names more
|
|
|
|
than it tries to supply a rigorously or consistently defined set of names,
|
|
|
|
and its detailed behavior may change across releases. For example,
|
|
|
|
metaclass attributes are not in the result list when the argument is a
|
|
|
|
class.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: divmod(a, b)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2021-07-19 13:02:23 -03:00
|
|
|
Take two (non-complex) numbers as arguments and return a pair of numbers
|
2009-05-17 10:00:36 -03:00
|
|
|
consisting of their quotient and remainder when using integer division. With
|
|
|
|
mixed operand types, the rules for binary arithmetic operators apply. For
|
|
|
|
integers, the result is the same as ``(a // b, a % b)``. For floating point
|
|
|
|
numbers the result is ``(q, a % b)``, where *q* is usually ``math.floor(a /
|
|
|
|
b)`` but may be 1 less than that. In any case ``q * b + a % b`` is very
|
|
|
|
close to *a*, if ``a % b`` is non-zero it has the same sign as *b*, and ``0
|
|
|
|
<= abs(a % b) < abs(b)``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2009-05-17 10:00:36 -03:00
|
|
|
.. function:: enumerate(iterable, start=0)
|
Merged revisions 63119-63128,63130-63131,63133,63135-63144,63146-63148,63151-63152,63155-63165,63167-63176,63181-63186,63188-63189 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r63119 | benjamin.peterson | 2008-05-11 20:41:23 -0400 (Sun, 11 May 2008) | 2 lines
#2196 hasattr now allows SystemExit and KeyboardInterrupt to propagate
........
r63122 | benjamin.peterson | 2008-05-11 20:46:49 -0400 (Sun, 11 May 2008) | 2 lines
make message slightly more informative, so there's no chance of misunderstanding it
........
r63158 | ronald.oussoren | 2008-05-12 07:24:33 -0400 (Mon, 12 May 2008) | 5 lines
Remove references to platform 'mac'
The 'mac' platform (that is, os.name == 'mac') was used for the MacOS 9 port,
which is no longer supported (as of Python 2.4 IIRC).
........
r63159 | ronald.oussoren | 2008-05-12 07:31:05 -0400 (Mon, 12 May 2008) | 8 lines
MacOSX: remove dependency on Carbon package for urllib
This patch removes the dependency on the Carbon package from urllib.
The mac-specific code for getting proxy configuration is now writting in
Python using ctypes and uses the SystemConfiguration framework instead of
InternetConfig. Also provides a mac-specific implementation of proxy_bypass.
........
r63162 | eric.smith | 2008-05-12 10:00:01 -0400 (Mon, 12 May 2008) | 1 line
Added 'n' presentation type for integers.
........
r63164 | georg.brandl | 2008-05-12 12:26:52 -0400 (Mon, 12 May 2008) | 2 lines
#1713041: fix pprint's handling of maximum depth.
........
r63170 | georg.brandl | 2008-05-12 12:53:42 -0400 (Mon, 12 May 2008) | 2 lines
Fix parameter name for enumerate().
........
r63173 | georg.brandl | 2008-05-12 13:01:58 -0400 (Mon, 12 May 2008) | 2 lines
#2766: remove code without effect.
........
r63174 | georg.brandl | 2008-05-12 13:04:10 -0400 (Mon, 12 May 2008) | 3 lines
#2767: don't clear globs in run() call, since they could be needed in tearDown,
which clears them at the end.
........
r63175 | georg.brandl | 2008-05-12 13:14:51 -0400 (Mon, 12 May 2008) | 2 lines
#1760: try-except-finally is one statement since PEP 341.
........
r63186 | amaury.forgeotdarc | 2008-05-12 17:30:24 -0400 (Mon, 12 May 2008) | 2 lines
Sync code with documentation, and remove Win95 support in winsound module.
........
r63189 | amaury.forgeotdarc | 2008-05-12 18:21:39 -0400 (Mon, 12 May 2008) | 3 lines
Adapt test_pyclbr to the new version of urllib.py:
The new mac-specific functions must be ignored.
........
2008-05-15 23:54:33 -03:00
|
|
|
|
2008-05-16 10:27:32 -03:00
|
|
|
Return an enumerate object. *iterable* must be a sequence, an
|
2012-10-12 07:42:08 -03:00
|
|
|
:term:`iterator`, or some other object which supports iteration.
|
|
|
|
The :meth:`~iterator.__next__` method of the iterator returned by
|
|
|
|
:func:`enumerate` returns a tuple containing a count (from *start* which
|
|
|
|
defaults to 0) and the values obtained from iterating over *iterable*.
|
2011-06-25 10:00:14 -03:00
|
|
|
|
|
|
|
>>> seasons = ['Spring', 'Summer', 'Fall', 'Winter']
|
|
|
|
>>> list(enumerate(seasons))
|
|
|
|
[(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]
|
|
|
|
>>> list(enumerate(seasons, start=1))
|
|
|
|
[(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')]
|
2011-06-01 20:17:23 -03:00
|
|
|
|
|
|
|
Equivalent to::
|
|
|
|
|
2023-01-14 01:55:35 -04:00
|
|
|
def enumerate(iterable, start=0):
|
2011-06-01 20:17:23 -03:00
|
|
|
n = start
|
2023-01-14 01:55:35 -04:00
|
|
|
for elem in iterable:
|
2011-06-01 20:17:23 -03:00
|
|
|
yield n, elem
|
|
|
|
n += 1
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-05-21 04:33:23 -03:00
|
|
|
.. _func-eval:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-12-31 20:59:31 -04:00
|
|
|
.. function:: eval(expression, globals=None, locals=None)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
The arguments are a string and optional globals and locals. If provided,
|
|
|
|
*globals* must be a dictionary. If provided, *locals* can be any mapping
|
|
|
|
object.
|
|
|
|
|
|
|
|
The *expression* argument is parsed and evaluated as a Python expression
|
|
|
|
(technically speaking, a condition list) using the *globals* and *locals*
|
#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
|
|
|
dictionaries as global and local namespace. If the *globals* dictionary is
|
2018-08-19 07:25:33 -03:00
|
|
|
present and does not contain a value for the key ``__builtins__``, a
|
|
|
|
reference to the dictionary of the built-in module :mod:`builtins` is
|
2020-12-16 11:45:19 -04:00
|
|
|
inserted under that key before *expression* is parsed. That way you can
|
|
|
|
control what builtins are available to the executed code by inserting your
|
|
|
|
own ``__builtins__`` dictionary into *globals* before passing it to
|
|
|
|
:func:`eval`. If the *locals* dictionary is omitted it defaults to the
|
|
|
|
*globals* dictionary. If both dictionaries are omitted, the expression is
|
|
|
|
executed with the *globals* and *locals* in the environment where
|
|
|
|
:func:`eval` is called. Note, *eval()* does not have access to the
|
|
|
|
:term:`nested scopes <nested scope>` (non-locals) in the enclosing
|
|
|
|
environment.
|
2019-08-06 21:56:22 -03:00
|
|
|
|
|
|
|
The return value is the result of
|
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
|
|
|
the evaluated expression. Syntax errors are reported as exceptions. Example:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
>>> x = 1
|
2007-09-04 04:15:32 -03:00
|
|
|
>>> eval('x+1')
|
2007-08-15 11:28:22 -03:00
|
|
|
2
|
|
|
|
|
Merged revisions 66045,66048-66049,66053,66060,66062-66063,66065,66067,66071-66074,66080,66082-66083,66090-66093,66097-66099,66103,66105,66110,66118 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r66045 | andrew.kuchling | 2008-08-26 19:27:18 -0500 (Tue, 26 Aug 2008) | 1 line
Trim whitespace; add a few updates
........
r66048 | andrew.kuchling | 2008-08-26 19:45:02 -0500 (Tue, 26 Aug 2008) | 1 line
Add an item and a note
........
r66049 | andrew.kuchling | 2008-08-26 21:12:18 -0500 (Tue, 26 Aug 2008) | 1 line
Add various items
........
r66053 | georg.brandl | 2008-08-28 04:40:18 -0500 (Thu, 28 Aug 2008) | 2 lines
#3711: .dll isn't a valid Python extension anymore.
........
r66060 | armin.rigo | 2008-08-29 16:21:52 -0500 (Fri, 29 Aug 2008) | 3 lines
A collection of crashers, all variants of the idea
of issue #3720.
........
r66062 | georg.brandl | 2008-08-30 04:49:36 -0500 (Sat, 30 Aug 2008) | 2 lines
#3730: mention "server" attribute explicitly.
........
r66063 | georg.brandl | 2008-08-30 04:52:44 -0500 (Sat, 30 Aug 2008) | 2 lines
#3716: fix typo.
........
r66065 | georg.brandl | 2008-08-30 05:03:09 -0500 (Sat, 30 Aug 2008) | 2 lines
#3569: eval() also accepts "exec"able code objects.
........
r66067 | georg.brandl | 2008-08-30 08:17:39 -0500 (Sat, 30 Aug 2008) | 2 lines
super() actually returns a super object.
........
r66071 | andrew.kuchling | 2008-08-30 10:19:57 -0500 (Sat, 30 Aug 2008) | 1 line
Partial edits from revision and tidying pass
........
r66072 | andrew.kuchling | 2008-08-30 10:21:23 -0500 (Sat, 30 Aug 2008) | 1 line
Tidy up some sentences
........
r66073 | andrew.kuchling | 2008-08-30 10:25:47 -0500 (Sat, 30 Aug 2008) | 1 line
Correction from Antoine Pitrou: BufferedWriter and Reader support seek()
........
r66074 | andrew.kuchling | 2008-08-30 11:44:54 -0500 (Sat, 30 Aug 2008) | 1 line
Edit four more sections
........
r66080 | georg.brandl | 2008-08-30 17:00:28 -0500 (Sat, 30 Aug 2008) | 2 lines
Fix markup.
........
r66082 | andrew.kuchling | 2008-08-30 17:56:54 -0500 (Sat, 30 Aug 2008) | 1 line
More edits; markup fixes
........
r66083 | andrew.kuchling | 2008-08-30 21:24:08 -0500 (Sat, 30 Aug 2008) | 1 line
More edits
........
r66090 | andrew.kuchling | 2008-08-31 09:29:31 -0500 (Sun, 31 Aug 2008) | 1 line
Edit the library section, rearranging items to flow better and making lots of edits
........
r66091 | andrew.kuchling | 2008-08-31 10:41:48 -0500 (Sun, 31 Aug 2008) | 1 line
Last batch of edits; remove the 'other changes' section
........
r66092 | andrew.kuchling | 2008-08-31 10:48:44 -0500 (Sun, 31 Aug 2008) | 1 line
Update patch/bug count
........
r66093 | gregory.p.smith | 2008-08-31 11:34:18 -0500 (Sun, 31 Aug 2008) | 3 lines
issue3715: docstring representation of hex escaped string needs to be double
escaped.
........
r66097 | benjamin.peterson | 2008-09-01 09:13:43 -0500 (Mon, 01 Sep 2008) | 4 lines
#3703 unhelpful _fileio.FileIO error message when trying to open a directory
Reviewer: Gregory P. Smith
........
r66098 | georg.brandl | 2008-09-01 09:15:55 -0500 (Mon, 01 Sep 2008) | 2 lines
#3749: fix c'n'p errors.
........
r66099 | benjamin.peterson | 2008-09-01 09:18:30 -0500 (Mon, 01 Sep 2008) | 4 lines
Fix compilation when --without-threads is given #3683
Reviewer: Georg Brandl, Benjamin Peterson
........
r66103 | vinay.sajip | 2008-09-01 09:30:10 -0500 (Mon, 01 Sep 2008) | 1 line
logging: fixed lack of use of encoding attribute specified on a stream.
........
r66105 | vinay.sajip | 2008-09-01 09:33:59 -0500 (Mon, 01 Sep 2008) | 1 line
logging: fixed lack of use of encoding attribute specified on a stream.
........
r66110 | vinay.sajip | 2008-09-01 10:08:07 -0500 (Mon, 01 Sep 2008) | 1 line
Added section about configuring logging in a library. Thanks to Thomas Heller for the idea.
........
r66118 | vinay.sajip | 2008-09-01 12:44:14 -0500 (Mon, 01 Sep 2008) | 1 line
Bug #3738: Documentation is now more accurate in describing handler close methods.
........
2008-09-01 21:31:15 -03:00
|
|
|
This function can also be used to execute arbitrary code objects (such as
|
2021-07-19 13:02:23 -03:00
|
|
|
those created by :func:`compile`). In this case, pass a code object instead
|
Merged revisions 66045,66048-66049,66053,66060,66062-66063,66065,66067,66071-66074,66080,66082-66083,66090-66093,66097-66099,66103,66105,66110,66118 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r66045 | andrew.kuchling | 2008-08-26 19:27:18 -0500 (Tue, 26 Aug 2008) | 1 line
Trim whitespace; add a few updates
........
r66048 | andrew.kuchling | 2008-08-26 19:45:02 -0500 (Tue, 26 Aug 2008) | 1 line
Add an item and a note
........
r66049 | andrew.kuchling | 2008-08-26 21:12:18 -0500 (Tue, 26 Aug 2008) | 1 line
Add various items
........
r66053 | georg.brandl | 2008-08-28 04:40:18 -0500 (Thu, 28 Aug 2008) | 2 lines
#3711: .dll isn't a valid Python extension anymore.
........
r66060 | armin.rigo | 2008-08-29 16:21:52 -0500 (Fri, 29 Aug 2008) | 3 lines
A collection of crashers, all variants of the idea
of issue #3720.
........
r66062 | georg.brandl | 2008-08-30 04:49:36 -0500 (Sat, 30 Aug 2008) | 2 lines
#3730: mention "server" attribute explicitly.
........
r66063 | georg.brandl | 2008-08-30 04:52:44 -0500 (Sat, 30 Aug 2008) | 2 lines
#3716: fix typo.
........
r66065 | georg.brandl | 2008-08-30 05:03:09 -0500 (Sat, 30 Aug 2008) | 2 lines
#3569: eval() also accepts "exec"able code objects.
........
r66067 | georg.brandl | 2008-08-30 08:17:39 -0500 (Sat, 30 Aug 2008) | 2 lines
super() actually returns a super object.
........
r66071 | andrew.kuchling | 2008-08-30 10:19:57 -0500 (Sat, 30 Aug 2008) | 1 line
Partial edits from revision and tidying pass
........
r66072 | andrew.kuchling | 2008-08-30 10:21:23 -0500 (Sat, 30 Aug 2008) | 1 line
Tidy up some sentences
........
r66073 | andrew.kuchling | 2008-08-30 10:25:47 -0500 (Sat, 30 Aug 2008) | 1 line
Correction from Antoine Pitrou: BufferedWriter and Reader support seek()
........
r66074 | andrew.kuchling | 2008-08-30 11:44:54 -0500 (Sat, 30 Aug 2008) | 1 line
Edit four more sections
........
r66080 | georg.brandl | 2008-08-30 17:00:28 -0500 (Sat, 30 Aug 2008) | 2 lines
Fix markup.
........
r66082 | andrew.kuchling | 2008-08-30 17:56:54 -0500 (Sat, 30 Aug 2008) | 1 line
More edits; markup fixes
........
r66083 | andrew.kuchling | 2008-08-30 21:24:08 -0500 (Sat, 30 Aug 2008) | 1 line
More edits
........
r66090 | andrew.kuchling | 2008-08-31 09:29:31 -0500 (Sun, 31 Aug 2008) | 1 line
Edit the library section, rearranging items to flow better and making lots of edits
........
r66091 | andrew.kuchling | 2008-08-31 10:41:48 -0500 (Sun, 31 Aug 2008) | 1 line
Last batch of edits; remove the 'other changes' section
........
r66092 | andrew.kuchling | 2008-08-31 10:48:44 -0500 (Sun, 31 Aug 2008) | 1 line
Update patch/bug count
........
r66093 | gregory.p.smith | 2008-08-31 11:34:18 -0500 (Sun, 31 Aug 2008) | 3 lines
issue3715: docstring representation of hex escaped string needs to be double
escaped.
........
r66097 | benjamin.peterson | 2008-09-01 09:13:43 -0500 (Mon, 01 Sep 2008) | 4 lines
#3703 unhelpful _fileio.FileIO error message when trying to open a directory
Reviewer: Gregory P. Smith
........
r66098 | georg.brandl | 2008-09-01 09:15:55 -0500 (Mon, 01 Sep 2008) | 2 lines
#3749: fix c'n'p errors.
........
r66099 | benjamin.peterson | 2008-09-01 09:18:30 -0500 (Mon, 01 Sep 2008) | 4 lines
Fix compilation when --without-threads is given #3683
Reviewer: Georg Brandl, Benjamin Peterson
........
r66103 | vinay.sajip | 2008-09-01 09:30:10 -0500 (Mon, 01 Sep 2008) | 1 line
logging: fixed lack of use of encoding attribute specified on a stream.
........
r66105 | vinay.sajip | 2008-09-01 09:33:59 -0500 (Mon, 01 Sep 2008) | 1 line
logging: fixed lack of use of encoding attribute specified on a stream.
........
r66110 | vinay.sajip | 2008-09-01 10:08:07 -0500 (Mon, 01 Sep 2008) | 1 line
Added section about configuring logging in a library. Thanks to Thomas Heller for the idea.
........
r66118 | vinay.sajip | 2008-09-01 12:44:14 -0500 (Mon, 01 Sep 2008) | 1 line
Bug #3738: Documentation is now more accurate in describing handler close methods.
........
2008-09-01 21:31:15 -03:00
|
|
|
of a string. If the code object has been compiled with ``'exec'`` as the
|
2010-03-21 06:04:24 -03:00
|
|
|
*mode* argument, :func:`eval`\'s return value will be ``None``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Hints: dynamic execution of statements is supported by the :func:`exec`
|
|
|
|
function. The :func:`globals` and :func:`locals` functions
|
2021-07-19 13:02:23 -03:00
|
|
|
return the current global and local dictionary, respectively, which may be
|
2007-08-15 11:28:22 -03:00
|
|
|
useful to pass around for use by :func:`eval` or :func:`exec`.
|
|
|
|
|
2020-10-03 21:46:44 -03:00
|
|
|
If the given source is a string, then leading and trailing spaces and tabs
|
|
|
|
are stripped.
|
|
|
|
|
2010-07-11 06:42:10 -03:00
|
|
|
See :func:`ast.literal_eval` for a function that can safely evaluate strings
|
|
|
|
with expressions containing only literals.
|
|
|
|
|
2019-06-27 14:47:59 -03:00
|
|
|
.. audit-event:: exec code_object eval
|
2019-05-23 12:45:22 -03:00
|
|
|
|
2019-06-24 12:42:54 -03:00
|
|
|
Raises an :ref:`auditing event <auditing>` ``exec`` with the code object
|
|
|
|
as the argument. Code compilation events may also be raised.
|
2019-05-23 12:45:22 -03:00
|
|
|
|
2023-05-06 00:54:08 -03:00
|
|
|
.. index:: pair: built-in function; exec
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-10-15 07:19:35 -03:00
|
|
|
.. function:: exec(object, globals=None, locals=None, /, *, closure=None)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-11-11 17:43:42 -04:00
|
|
|
This function supports dynamic execution of Python code. *object* must be
|
|
|
|
either a string or a code object. If it is a string, the string is parsed as
|
|
|
|
a suite of Python statements which is then executed (unless a syntax error
|
2009-03-31 13:57:13 -03:00
|
|
|
occurs). [#]_ If it is a code object, it is simply executed. In all cases,
|
|
|
|
the code that's executed is expected to be valid as file input (see the
|
2021-11-02 18:34:00 -03:00
|
|
|
section :ref:`file-input` in the Reference Manual). Be aware that the
|
2021-02-07 01:28:50 -04:00
|
|
|
:keyword:`nonlocal`, :keyword:`yield`, and :keyword:`return`
|
|
|
|
statements may not be used outside of
|
2009-03-31 13:57:13 -03:00
|
|
|
function definitions even within the context of code passed to the
|
|
|
|
:func:`exec` function. The return value is ``None``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
In all cases, if the optional parts are omitted, the code is executed in the
|
2019-06-01 12:51:58 -03:00
|
|
|
current scope. If only *globals* is provided, it must be a dictionary
|
|
|
|
(and not a subclass of dictionary), which
|
2007-08-15 11:28:22 -03:00
|
|
|
will be used for both the global and the local variables. If *globals* and
|
|
|
|
*locals* are given, they are used for the global and local variables,
|
2012-07-08 18:36:14 -03:00
|
|
|
respectively. If provided, *locals* can be any mapping object. Remember
|
2021-07-19 13:02:23 -03:00
|
|
|
that at the module level, globals and locals are the same dictionary. If exec
|
2012-07-08 18:36:14 -03:00
|
|
|
gets two separate objects as *globals* and *locals*, the code will be
|
|
|
|
executed as if it were embedded in a class definition.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
If the *globals* dictionary does not contain a value for the key
|
|
|
|
``__builtins__``, a reference to the dictionary of the built-in module
|
2007-12-02 05:40:06 -04:00
|
|
|
:mod:`builtins` is inserted under that key. That way you can control what
|
2007-08-15 11:28:22 -03:00
|
|
|
builtins are available to the executed code by inserting your own
|
|
|
|
``__builtins__`` dictionary into *globals* before passing it to :func:`exec`.
|
|
|
|
|
2022-05-06 14:09:35 -03:00
|
|
|
The *closure* argument specifies a closure--a tuple of cellvars.
|
|
|
|
It's only valid when the *object* is a code object containing free variables.
|
|
|
|
The length of the tuple must exactly match the number of free variables
|
|
|
|
referenced by the code object.
|
|
|
|
|
2019-06-27 14:47:59 -03:00
|
|
|
.. audit-event:: exec code_object exec
|
2019-05-23 12:45:22 -03:00
|
|
|
|
2019-06-24 12:42:54 -03:00
|
|
|
Raises an :ref:`auditing event <auditing>` ``exec`` with the code object
|
|
|
|
as the argument. Code compilation events may also be raised.
|
2019-05-23 12:45:22 -03:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
The built-in functions :func:`globals` and :func:`locals` return the current
|
|
|
|
global and local dictionary, respectively, which may be useful to pass around
|
|
|
|
for use as the second and third argument to :func:`exec`.
|
|
|
|
|
2009-04-27 13:20:50 -03:00
|
|
|
.. note::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
The default *locals* act as described for function :func:`locals` below:
|
2008-02-01 07:56:49 -04:00
|
|
|
modifications to the default *locals* dictionary should not be attempted.
|
|
|
|
Pass an explicit *locals* dictionary if you need to see effects of the
|
|
|
|
code on *locals* after function :func:`exec` returns.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-05-06 14:09:35 -03:00
|
|
|
.. versionchanged:: 3.11
|
|
|
|
Added the *closure* parameter.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: filter(function, iterable)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2007-09-04 14:50:40 -03:00
|
|
|
Construct an iterator from those elements of *iterable* for which *function*
|
2023-02-24 12:13:05 -04:00
|
|
|
is true. *iterable* may be either a sequence, a container which
|
#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
|
|
|
supports iteration, or an iterator. If *function* is ``None``, the identity
|
|
|
|
function is assumed, that is, all elements of *iterable* that are false are
|
|
|
|
removed.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2007-09-04 14:50:40 -03:00
|
|
|
Note that ``filter(function, iterable)`` is equivalent to the generator
|
|
|
|
expression ``(item for item in iterable if function(item))`` if function is
|
|
|
|
not ``None`` and ``(item for item in iterable if item)`` if function is
|
|
|
|
``None``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2009-02-19 00:45:07 -04:00
|
|
|
See :func:`itertools.filterfalse` for the complementary function that returns
|
2023-02-24 12:13:05 -04:00
|
|
|
elements of *iterable* for which *function* is false.
|
2009-02-19 00:45:07 -04:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. class:: float(x=0.0)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-11-21 17:09:58 -04:00
|
|
|
.. index::
|
|
|
|
single: NaN
|
|
|
|
single: Infinity
|
|
|
|
|
2014-10-06 08:54:36 -03:00
|
|
|
Return a floating point number constructed from a number or string *x*.
|
2010-11-21 17:09:58 -04:00
|
|
|
|
|
|
|
If the argument is a string, it should contain a decimal number, optionally
|
|
|
|
preceded by a sign, and optionally embedded in whitespace. The optional
|
|
|
|
sign may be ``'+'`` or ``'-'``; a ``'+'`` sign has no effect on the value
|
|
|
|
produced. The argument may also be a string representing a NaN
|
2021-07-19 13:02:23 -03:00
|
|
|
(not-a-number), or positive or negative infinity. More precisely, the
|
2022-12-24 16:09:31 -04:00
|
|
|
input must conform to the ``floatvalue`` production rule in the following
|
|
|
|
grammar, after leading and trailing whitespace characters are removed:
|
2010-11-21 17:09:58 -04:00
|
|
|
|
2020-09-18 04:10:15 -03:00
|
|
|
.. productionlist:: float
|
2010-11-21 17:09:58 -04:00
|
|
|
sign: "+" | "-"
|
|
|
|
infinity: "Infinity" | "inf"
|
|
|
|
nan: "nan"
|
2022-12-24 16:09:31 -04:00
|
|
|
digitpart: `digit` (["_"] `digit`)*
|
|
|
|
number: [`digitpart`] "." `digitpart` | `digitpart` ["."]
|
|
|
|
exponent: ("e" | "E") ["+" | "-"] `digitpart`
|
|
|
|
floatnumber: number [`exponent`]
|
|
|
|
floatvalue: [`sign`] (`floatnumber` | `infinity` | `nan`)
|
|
|
|
|
|
|
|
Here ``digit`` is a Unicode decimal digit (character in the Unicode general
|
|
|
|
category ``Nd``). Case is not significant, so, for example, "inf", "Inf",
|
|
|
|
"INFINITY", and "iNfINity" are all acceptable spellings for positive
|
|
|
|
infinity.
|
2010-11-21 17:09:58 -04:00
|
|
|
|
|
|
|
Otherwise, if the argument is an integer or a floating point number, a
|
|
|
|
floating point number with the same value (within Python's floating point
|
|
|
|
precision) is returned. If the argument is outside the range of a Python
|
|
|
|
float, an :exc:`OverflowError` will be raised.
|
|
|
|
|
|
|
|
For a general Python object ``x``, ``float(x)`` delegates to
|
2023-06-30 11:27:09 -03:00
|
|
|
``x.__float__()``. If :meth:`~object.__float__` is not defined then it falls back
|
|
|
|
to :meth:`~object.__index__`.
|
2010-11-21 17:09:58 -04:00
|
|
|
|
|
|
|
If no argument is given, ``0.0`` is returned.
|
|
|
|
|
|
|
|
Examples::
|
|
|
|
|
|
|
|
>>> float('+1.23')
|
|
|
|
1.23
|
|
|
|
>>> float(' -12345\n')
|
|
|
|
-12345.0
|
|
|
|
>>> float('1e-003')
|
|
|
|
0.001
|
|
|
|
>>> float('+1E6')
|
|
|
|
1000000.0
|
|
|
|
>>> float('-Infinity')
|
|
|
|
-inf
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
The float type is described in :ref:`typesnumeric`.
|
|
|
|
|
2016-09-09 18:57:09 -03:00
|
|
|
.. versionchanged:: 3.6
|
|
|
|
Grouping digits with underscores as in code literals is allowed.
|
|
|
|
|
2018-08-27 07:45:26 -03:00
|
|
|
.. versionchanged:: 3.7
|
|
|
|
*x* is now a positional-only parameter.
|
|
|
|
|
2019-06-01 18:05:48 -03:00
|
|
|
.. versionchanged:: 3.8
|
2023-06-30 11:27:09 -03:00
|
|
|
Falls back to :meth:`~object.__index__` if :meth:`~object.__float__` is not defined.
|
2019-06-01 18:05:48 -03:00
|
|
|
|
2012-11-28 05:38:40 -04:00
|
|
|
|
2016-09-09 18:57:09 -03:00
|
|
|
.. index::
|
|
|
|
single: __format__
|
|
|
|
single: string; format() (built-in function)
|
2012-11-28 05:38:40 -04:00
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: format(value, format_spec="")
|
2009-01-03 17:18:54 -04:00
|
|
|
|
2009-02-23 06:24:05 -04:00
|
|
|
Convert a *value* to a "formatted" representation, as controlled by
|
|
|
|
*format_spec*. The interpretation of *format_spec* will depend on the type
|
2021-07-19 13:02:23 -03:00
|
|
|
of the *value* argument; however, there is a standard formatting syntax that
|
2009-02-23 06:24:05 -04:00
|
|
|
is used by most built-in types: :ref:`formatspec`.
|
2009-01-03 17:18:54 -04:00
|
|
|
|
2011-05-11 14:47:27 -03:00
|
|
|
The default *format_spec* is an empty string which usually gives the same
|
2012-11-20 21:45:51 -04:00
|
|
|
effect as calling :func:`str(value) <str>`.
|
2011-05-11 14:47:27 -03:00
|
|
|
|
|
|
|
A call to ``format(value, format_spec)`` is translated to
|
2014-10-31 05:41:46 -03:00
|
|
|
``type(value).__format__(value, format_spec)`` which bypasses the instance
|
2011-05-11 14:47:27 -03:00
|
|
|
dictionary when searching for the value's :meth:`__format__` method. A
|
2014-03-16 01:13:56 -03:00
|
|
|
:exc:`TypeError` exception is raised if the method search reaches
|
|
|
|
:mod:`object` and the *format_spec* is non-empty, or if either the
|
|
|
|
*format_spec* or the return value are not strings.
|
2007-08-31 06:22:56 -03:00
|
|
|
|
2014-03-16 01:13:56 -03:00
|
|
|
.. versionchanged:: 3.4
|
2012-12-23 09:12:19 -04:00
|
|
|
``object().__format__(format_spec)`` raises :exc:`TypeError`
|
2014-03-16 01:13:56 -03:00
|
|
|
if *format_spec* is not an empty string.
|
2012-12-23 09:12:19 -04:00
|
|
|
|
2011-09-01 18:08:55 -03:00
|
|
|
|
|
|
|
.. _func-frozenset:
|
2022-11-19 06:25:45 -04:00
|
|
|
.. class:: frozenset(iterable=set())
|
2007-08-15 11:28:22 -03:00
|
|
|
:noindex:
|
|
|
|
|
2012-11-09 22:57:32 -04:00
|
|
|
Return a new :class:`frozenset` object, optionally with elements taken from
|
|
|
|
*iterable*. ``frozenset`` is a built-in class. See :class:`frozenset` and
|
|
|
|
:ref:`types-set` for documentation about this class.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-11-09 22:57:32 -04:00
|
|
|
For other containers see the built-in :class:`set`, :class:`list`,
|
|
|
|
:class:`tuple`, and :class:`dict` classes, as well as the :mod:`collections`
|
|
|
|
module.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: getattr(object, name)
|
|
|
|
getattr(object, name, default)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-10-16 15:51:05 -03:00
|
|
|
Return the value of the named attribute of *object*. *name* must be a string.
|
2007-08-15 11:28:22 -03:00
|
|
|
If the string is the name of one of the object's attributes, the result is the
|
|
|
|
value of that attribute. For example, ``getattr(x, 'foobar')`` is equivalent to
|
|
|
|
``x.foobar``. If the named attribute does not exist, *default* is returned if
|
|
|
|
provided, otherwise :exc:`AttributeError` is raised.
|
2022-09-29 20:02:27 -03:00
|
|
|
*name* need not be a Python identifier (see :func:`setattr`).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2021-02-02 17:06:57 -04:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
Since :ref:`private name mangling <private-name-mangling>` happens at
|
|
|
|
compilation time, one must manually mangle a private attribute's
|
|
|
|
(attributes with two leading underscores) name in order to retrieve it with
|
|
|
|
:func:`getattr`.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. function:: globals()
|
|
|
|
|
2021-12-10 20:04:21 -04:00
|
|
|
Return the dictionary implementing the current module namespace. For code within
|
|
|
|
functions, this is set when the function is defined and remains the same
|
|
|
|
regardless of where the function is called.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: hasattr(object, name)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-08-24 00:26:23 -03:00
|
|
|
The arguments are an object and a string. The result is ``True`` if the
|
|
|
|
string is the name of one of the object's attributes, ``False`` if not. (This
|
|
|
|
is implemented by calling ``getattr(object, name)`` and seeing whether it
|
|
|
|
raises an :exc:`AttributeError` or not.)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: hash(object)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2013-07-15 15:47:29 -03:00
|
|
|
Return the hash value of the object (if it has one). Hash values are
|
|
|
|
integers. They are used to quickly compare dictionary keys during a
|
|
|
|
dictionary lookup. Numeric values that compare equal have the same hash
|
|
|
|
value (even if they are of different types, as is the case for 1 and 1.0).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2018-06-29 06:57:10 -03:00
|
|
|
.. note::
|
2013-07-15 15:47:29 -03:00
|
|
|
|
2018-06-29 06:57:10 -03:00
|
|
|
For objects with custom :meth:`__hash__` methods, note that :func:`hash`
|
|
|
|
truncates the return value based on the bit width of the host machine.
|
|
|
|
See :meth:`__hash__` for details.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-10-15 07:19:35 -03:00
|
|
|
.. function:: help()
|
|
|
|
help(request)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Invoke the built-in help system. (This function is intended for interactive
|
|
|
|
use.) If no argument is given, the interactive help system starts on the
|
|
|
|
interpreter console. If the argument is a string, then the string is looked up
|
|
|
|
as the name of a module, function, class, method, keyword, or documentation
|
|
|
|
topic, and a help page is printed on the console. If the argument is any other
|
|
|
|
kind of object, a help page on the object is generated.
|
|
|
|
|
2021-07-19 13:02:23 -03:00
|
|
|
Note that if a slash(/) appears in the parameter list of a function when
|
2019-03-10 08:30:11 -03:00
|
|
|
invoking :func:`help`, it means that the parameters prior to the slash are
|
|
|
|
positional-only. For more info, see
|
|
|
|
:ref:`the FAQ entry on positional-only parameters <faq-positional-only-arguments>`.
|
|
|
|
|
Merged revisions 60124-60142 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60131 | georg.brandl | 2008-01-20 12:13:29 +0100 (Sun, 20 Jan 2008) | 3 lines
#1351692: in pprint, always call format() for dict and list items to enable
custom formatting of contents via subclassing PrettyPrinter.
........
r60133 | georg.brandl | 2008-01-20 12:43:03 +0100 (Sun, 20 Jan 2008) | 2 lines
#1178141: add addinfourl.code to get http status code from urllib.
........
r60134 | georg.brandl | 2008-01-20 13:05:43 +0100 (Sun, 20 Jan 2008) | 4 lines
#856047: respect the ``no_proxy`` env var when checking for proxies
in urllib and using the other ``_proxy`` env vars.
Original patch by Donovan Baarda.
........
r60135 | georg.brandl | 2008-01-20 13:18:17 +0100 (Sun, 20 Jan 2008) | 4 lines
#1664522: in urllib, don't read non-existing directories in ftp mode,
returning a 0-byte file -- raise an IOError instead.
Original patch from Phil Knirsch.
........
r60136 | georg.brandl | 2008-01-20 13:57:47 +0100 (Sun, 20 Jan 2008) | 2 lines
#799369: document possible sys.platform values.
........
r60137 | georg.brandl | 2008-01-20 14:08:37 +0100 (Sun, 20 Jan 2008) | 2 lines
#652749: document the constants added to the builtins by site.py.
........
r60138 | georg.brandl | 2008-01-20 14:59:46 +0100 (Sun, 20 Jan 2008) | 2 lines
#1648: add sys.gettrace() and sys.getprofile().
........
r60139 | georg.brandl | 2008-01-20 15:17:42 +0100 (Sun, 20 Jan 2008) | 2 lines
#1669: don't allow shutil.rmtree() to be called on a symlink.
........
r60140 | georg.brandl | 2008-01-20 15:20:02 +0100 (Sun, 20 Jan 2008) | 2 lines
Fix test_pyclbr after urllib change.
........
r60141 | christian.heimes | 2008-01-20 15:28:28 +0100 (Sun, 20 Jan 2008) | 1 line
Fixed a wrong assumption in configure.in and Include/pyport.h. The is finite function is not called isfinite() but finite(). Sorry, my fault. :)
........
r60142 | georg.brandl | 2008-01-20 15:31:27 +0100 (Sun, 20 Jan 2008) | 2 lines
#1876: fix typos in test_operator.
........
2008-01-20 11:14:11 -04:00
|
|
|
This function is added to the built-in namespace by the :mod:`site` module.
|
|
|
|
|
2014-03-16 01:13:56 -03:00
|
|
|
.. versionchanged:: 3.4
|
|
|
|
Changes to :mod:`pydoc` and :mod:`inspect` mean that the reported
|
|
|
|
signatures for callables are now more comprehensive and consistent.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: hex(x)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-07-06 16:30:58 -03:00
|
|
|
Convert an integer number to a lowercase hexadecimal string prefixed with
|
2018-05-10 10:38:44 -03:00
|
|
|
"0x". If *x* is not a Python :class:`int` object, it has to define an
|
2023-06-30 11:27:09 -03:00
|
|
|
:meth:`~object.__index__` method that returns an integer. Some examples:
|
2014-03-16 01:13:56 -03:00
|
|
|
|
|
|
|
>>> hex(255)
|
|
|
|
'0xff'
|
|
|
|
>>> hex(-42)
|
|
|
|
'-0x2a'
|
|
|
|
|
2017-07-06 16:30:58 -03:00
|
|
|
If you want to convert an integer number to an uppercase or lower hexadecimal
|
|
|
|
string with prefix or not, you can use either of the following ways:
|
|
|
|
|
|
|
|
>>> '%#x' % 255, '%x' % 255, '%X' % 255
|
|
|
|
('0xff', 'ff', 'FF')
|
|
|
|
>>> format(255, '#x'), format(255, 'x'), format(255, 'X')
|
|
|
|
('0xff', 'ff', 'FF')
|
|
|
|
>>> f'{255:#x}', f'{255:x}', f'{255:X}'
|
|
|
|
('0xff', 'ff', 'FF')
|
|
|
|
|
|
|
|
See also :func:`format` for more information.
|
2014-03-16 01:13:56 -03:00
|
|
|
|
|
|
|
See also :func:`int` for converting a hexadecimal string to an
|
|
|
|
integer using a base of 16.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2009-10-03 07:18:40 -03:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
To obtain a hexadecimal string representation for a float, use the
|
|
|
|
:meth:`float.hex` method.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: id(object)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2007-11-29 13:24:34 -04:00
|
|
|
Return the "identity" of an object. This is an integer which
|
2007-08-15 11:28:22 -03:00
|
|
|
is guaranteed to be unique and constant for this object during its lifetime.
|
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
|
|
|
Two objects with non-overlapping lifetimes may have the same :func:`id`
|
|
|
|
value.
|
|
|
|
|
2011-05-26 23:42:47 -03:00
|
|
|
.. impl-detail:: This is the address of the object in memory.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2020-10-20 16:23:15 -03:00
|
|
|
.. audit-event:: builtins.id id id
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-10-15 07:19:35 -03:00
|
|
|
.. function:: input()
|
2022-11-19 06:25:45 -04:00
|
|
|
input(prompt)
|
2007-09-12 18:29:27 -03:00
|
|
|
|
|
|
|
If the *prompt* argument is present, it is written to standard output without
|
|
|
|
a trailing newline. The function then reads a line from input, converts it
|
|
|
|
to a string (stripping a trailing newline), and returns that. When EOF is
|
|
|
|
read, :exc:`EOFError` is raised. Example::
|
|
|
|
|
2012-08-12 09:16:42 -03:00
|
|
|
>>> s = input('--> ') # doctest: +SKIP
|
2007-09-12 18:29:27 -03:00
|
|
|
--> Monty Python's Flying Circus
|
2012-08-12 09:16:42 -03:00
|
|
|
>>> s # doctest: +SKIP
|
2007-09-12 18:29:27 -03:00
|
|
|
"Monty Python's Flying Circus"
|
|
|
|
|
2007-09-12 18:32:27 -03:00
|
|
|
If the :mod:`readline` module was loaded, then :func:`input` will use it
|
2007-09-12 18:29:27 -03:00
|
|
|
to provide elaborate line editing and history features.
|
|
|
|
|
2019-06-27 14:47:59 -03:00
|
|
|
.. audit-event:: builtins.input prompt input
|
2019-05-23 12:45:22 -03:00
|
|
|
|
2019-06-24 12:42:54 -03:00
|
|
|
Raises an :ref:`auditing event <auditing>` ``builtins.input`` with
|
2019-05-23 12:45:22 -03:00
|
|
|
argument ``prompt`` before reading input
|
|
|
|
|
2019-06-27 14:47:59 -03:00
|
|
|
.. audit-event:: builtins.input/result result input
|
2019-05-23 12:45:22 -03:00
|
|
|
|
2022-05-08 20:21:19 -03:00
|
|
|
Raises an :ref:`auditing event <auditing>` ``builtins.input/result``
|
|
|
|
with the result after successfully reading input.
|
2019-05-23 12:45:22 -03:00
|
|
|
|
2007-09-12 18:29:27 -03:00
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. class:: int(x=0)
|
|
|
|
int(x, base=10)
|
2012-09-28 04:10:44 -03:00
|
|
|
|
2014-10-06 08:54:36 -03:00
|
|
|
Return an integer object constructed from a number or string *x*, or return
|
2023-06-30 11:27:09 -03:00
|
|
|
``0`` if no arguments are given. If *x* defines :meth:`~object.__int__`,
|
|
|
|
``int(x)`` returns ``x.__int__()``. If *x* defines :meth:`~object.__index__`,
|
|
|
|
it returns ``x.__index__()``. If *x* defines :meth:`~object.__trunc__`,
|
2018-05-10 10:38:44 -03:00
|
|
|
it returns ``x.__trunc__()``.
|
|
|
|
For floating point numbers, this truncates towards zero.
|
2012-09-28 04:10:44 -03:00
|
|
|
|
|
|
|
If *x* is not a number or if *base* is given, then *x* must be a string,
|
2023-01-01 23:14:18 -04:00
|
|
|
:class:`bytes`, or :class:`bytearray` instance representing an integer
|
|
|
|
in radix *base*. Optionally, the string can be preceded by ``+`` or ``-``
|
|
|
|
(with no space in between), have leading zeros, be surrounded by whitespace,
|
|
|
|
and have single underscores interspersed between digits.
|
|
|
|
|
|
|
|
A base-n integer string contains digits, each representing a value from 0 to
|
|
|
|
n-1. The values 0--9 can be represented by any Unicode decimal digit. The
|
|
|
|
values 10--35 can be represented by ``a`` to ``z`` (or ``A`` to ``Z``). The
|
|
|
|
default *base* is 10. The allowed bases are 0 and 2--36. Base-2, -8, and -16
|
|
|
|
strings can be optionally prefixed with ``0b``/``0B``, ``0o``/``0O``, or
|
|
|
|
``0x``/``0X``, as with integer literals in code. For base 0, the string is
|
|
|
|
interpreted in a similar way to an :ref:`integer literal in code <integers>`,
|
|
|
|
in that the actual base is 2, 8, 10, or 16 as determined by the prefix. Base
|
|
|
|
0 also disallows leading zeros: ``int('010', 0)`` is not legal, while
|
|
|
|
``int('010')`` and ``int('010', 8)`` are.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
The integer type is described in :ref:`typesnumeric`.
|
|
|
|
|
2013-01-27 06:17:52 -04:00
|
|
|
.. versionchanged:: 3.4
|
|
|
|
If *base* is not an instance of :class:`int` and the *base* object has a
|
|
|
|
:meth:`base.__index__ <object.__index__>` method, that method is called
|
|
|
|
to obtain an integer for the base. Previous versions used
|
|
|
|
:meth:`base.__int__ <object.__int__>` instead of :meth:`base.__index__
|
|
|
|
<object.__index__>`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2016-09-09 18:57:09 -03:00
|
|
|
.. versionchanged:: 3.6
|
|
|
|
Grouping digits with underscores as in code literals is allowed.
|
|
|
|
|
2018-08-27 07:45:26 -03:00
|
|
|
.. versionchanged:: 3.7
|
|
|
|
*x* is now a positional-only parameter.
|
|
|
|
|
2019-06-01 18:05:48 -03:00
|
|
|
.. versionchanged:: 3.8
|
2023-06-30 11:27:09 -03:00
|
|
|
Falls back to :meth:`~object.__index__` if :meth:`~object.__int__` is not defined.
|
2019-06-01 18:05:48 -03:00
|
|
|
|
2022-02-03 05:43:25 -04:00
|
|
|
.. versionchanged:: 3.11
|
2023-06-30 11:27:09 -03:00
|
|
|
The delegation to :meth:`~object.__trunc__` is deprecated.
|
2022-02-03 05:43:25 -04:00
|
|
|
|
2022-09-19 20:43:11 -03:00
|
|
|
.. versionchanged:: 3.11
|
2022-09-02 13:35:08 -03:00
|
|
|
:class:`int` string inputs and string representations can be limited to
|
|
|
|
help avoid denial of service attacks. A :exc:`ValueError` is raised when
|
|
|
|
the limit is exceeded while converting a string *x* to an :class:`int` or
|
|
|
|
when converting an :class:`int` into a string would exceed the limit.
|
|
|
|
See the :ref:`integer string conversion length limitation
|
|
|
|
<int_max_str_digits>` documentation.
|
2016-09-09 18:57:09 -03:00
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: isinstance(object, classinfo)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2019-11-12 10:57:03 -04:00
|
|
|
Return ``True`` if the *object* argument is an instance of the *classinfo*
|
2021-07-19 13:02:23 -03:00
|
|
|
argument, or of a (direct, indirect, or :term:`virtual <abstract base
|
2011-08-18 21:17:03 -03:00
|
|
|
class>`) subclass thereof. If *object* is not
|
2019-11-12 10:57:03 -04:00
|
|
|
an object of the given type, the function always returns ``False``.
|
2015-10-28 04:14:56 -03:00
|
|
|
If *classinfo* is a tuple of type objects (or recursively, other such
|
2021-02-08 21:57:11 -04:00
|
|
|
tuples) or a :ref:`types-union` of multiple types, return ``True`` if
|
|
|
|
*object* is an instance of any of the types.
|
2015-10-28 04:14:56 -03:00
|
|
|
If *classinfo* is not a type or tuple of types and such tuples,
|
2022-04-28 12:24:19 -03:00
|
|
|
a :exc:`TypeError` exception is raised. :exc:`TypeError` may not be
|
|
|
|
raised for an invalid type if an earlier check succeeds.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2021-02-08 21:57:11 -04:00
|
|
|
.. versionchanged:: 3.10
|
|
|
|
*classinfo* can be a :ref:`types-union`.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: issubclass(class, classinfo)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2021-07-19 13:02:23 -03:00
|
|
|
Return ``True`` if *class* is a subclass (direct, indirect, or :term:`virtual
|
2011-08-18 21:17:03 -03:00
|
|
|
<abstract base class>`) of *classinfo*. A
|
2007-08-15 11:28:22 -03:00
|
|
|
class is considered a subclass of itself. *classinfo* may be a tuple of class
|
2022-05-01 01:05:20 -03:00
|
|
|
objects (or recursively, other such tuples)
|
|
|
|
or a :ref:`types-union`, in which case return ``True`` if *class* is a
|
2021-08-31 10:39:19 -03:00
|
|
|
subclass of any entry in *classinfo*. In any other case, a :exc:`TypeError`
|
|
|
|
exception is raised.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2021-02-08 21:57:11 -04:00
|
|
|
.. versionchanged:: 3.10
|
|
|
|
*classinfo* can be a :ref:`types-union`.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: iter(object)
|
|
|
|
iter(object, sentinel)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2009-05-17 10:00:36 -03:00
|
|
|
Return an :term:`iterator` object. The first argument is interpreted very
|
|
|
|
differently depending on the presence of the second argument. Without a
|
|
|
|
second argument, *object* must be a collection object which supports the
|
2021-11-19 20:40:34 -04:00
|
|
|
:term:`iterable` protocol (the :meth:`__iter__` method), or it must support
|
|
|
|
the sequence protocol (the :meth:`__getitem__` method with integer arguments
|
2009-05-17 10:00:36 -03:00
|
|
|
starting at ``0``). If it does not support either of those protocols,
|
|
|
|
:exc:`TypeError` is raised. If the second argument, *sentinel*, is given,
|
|
|
|
then *object* must be a callable object. The iterator created in this case
|
2012-10-12 07:42:08 -03:00
|
|
|
will call *object* with no arguments for each call to its
|
|
|
|
:meth:`~iterator.__next__` method; if the value returned is equal to
|
|
|
|
*sentinel*, :exc:`StopIteration` will be raised, otherwise the value will
|
|
|
|
be returned.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-10-13 00:28:26 -03:00
|
|
|
See also :ref:`typeiter`.
|
|
|
|
|
2018-12-24 01:07:17 -04:00
|
|
|
One useful application of the second form of :func:`iter` is to build a
|
|
|
|
block-reader. For example, reading fixed-width blocks from a binary
|
|
|
|
database file until the end of file is reached::
|
|
|
|
|
|
|
|
from functools import partial
|
|
|
|
with open('mydata.db', 'rb') as f:
|
2019-02-21 03:53:06 -04:00
|
|
|
for block in iter(partial(f.read, 64), b''):
|
2018-12-24 01:07:17 -04:00
|
|
|
process_block(block)
|
Merged revisions 70342,70385-70387,70389-70390,70392-70393,70395,70400,70405-70406,70418,70438,70464,70468 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r70342 | georg.brandl | 2009-03-13 14:03:58 -0500 (Fri, 13 Mar 2009) | 1 line
#5486: typos.
........
r70385 | benjamin.peterson | 2009-03-15 09:38:55 -0500 (Sun, 15 Mar 2009) | 1 line
fix tuple.index() error message #5495
........
r70386 | georg.brandl | 2009-03-15 16:32:06 -0500 (Sun, 15 Mar 2009) | 1 line
#5496: fix docstring of lookup().
........
r70387 | georg.brandl | 2009-03-15 16:37:16 -0500 (Sun, 15 Mar 2009) | 1 line
#5493: clarify __nonzero__ docs.
........
r70389 | georg.brandl | 2009-03-15 16:43:38 -0500 (Sun, 15 Mar 2009) | 1 line
Fix a small nit in the error message if bool() falls back on __len__ and it returns the wrong type: it would tell the user that __nonzero__ should return bool or int.
........
r70390 | georg.brandl | 2009-03-15 16:44:43 -0500 (Sun, 15 Mar 2009) | 1 line
#5491: clarify nested() semantics.
........
r70392 | georg.brandl | 2009-03-15 16:46:00 -0500 (Sun, 15 Mar 2009) | 1 line
#5488: add missing struct member.
........
r70393 | georg.brandl | 2009-03-15 16:47:42 -0500 (Sun, 15 Mar 2009) | 1 line
#5478: fix copy-paste oversight in function signature.
........
r70395 | georg.brandl | 2009-03-15 16:51:48 -0500 (Sun, 15 Mar 2009) | 1 line
#5276: document IDLESTARTUP and .Idle.py.
........
r70400 | georg.brandl | 2009-03-15 16:59:37 -0500 (Sun, 15 Mar 2009) | 3 lines
Fix markup in re docs and give a mail address in regex howto, so that
the recommendation to send suggestions to the author can be followed.
........
r70405 | georg.brandl | 2009-03-15 17:11:07 -0500 (Sun, 15 Mar 2009) | 7 lines
Move the previously local import of threading to module level.
This is cleaner and avoids lockups in obscure cases where a Queue
is instantiated while the import lock is already held by another thread.
OKed by Tim Peters.
........
r70406 | hirokazu.yamamoto | 2009-03-15 17:43:14 -0500 (Sun, 15 Mar 2009) | 1 line
Added skip for old MSVC.
........
r70418 | georg.brandl | 2009-03-16 14:42:03 -0500 (Mon, 16 Mar 2009) | 1 line
Add token markup.
........
r70438 | benjamin.peterson | 2009-03-17 15:29:51 -0500 (Tue, 17 Mar 2009) | 1 line
I thought this was begging for an example
........
r70464 | benjamin.peterson | 2009-03-18 15:58:09 -0500 (Wed, 18 Mar 2009) | 1 line
a much better example
........
r70468 | benjamin.peterson | 2009-03-18 22:04:31 -0500 (Wed, 18 Mar 2009) | 1 line
close files after comparing them
........
2009-03-21 14:31:58 -03:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: len(s)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Return the length (the number of items) of an object. The argument may be a
|
2014-06-16 04:05:37 -03:00
|
|
|
sequence (such as a string, bytes, tuple, list, or range) or a collection
|
|
|
|
(such as a dictionary, set, or frozen set).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2020-01-12 05:04:14 -04:00
|
|
|
.. impl-detail::
|
|
|
|
|
|
|
|
``len`` raises :exc:`OverflowError` on lengths larger than
|
|
|
|
:data:`sys.maxsize`, such as :class:`range(2 ** 100) <range>`.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
.. _func-list:
|
2022-10-15 07:19:35 -03:00
|
|
|
.. class:: list()
|
2022-11-19 06:25:45 -04:00
|
|
|
list(iterable)
|
2012-08-21 04:42:52 -03:00
|
|
|
:noindex:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
Rather than being a function, :class:`list` is actually a mutable
|
2012-10-13 00:28:26 -03:00
|
|
|
sequence type, as documented in :ref:`typesseq-list` and :ref:`typesseq`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2009-05-17 10:00:36 -03:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. function:: locals()
|
|
|
|
|
|
|
|
Update and return a dictionary representing the current local symbol table.
|
Merged revisions 74779-74786,74793,74795,74811,74860-74861,74863,74876,74886,74896,74901,74903,74908,74912,74930,74933,74943,74946,74952-74955,75015,75019,75032,75068,75076,75095,75098,75102,75129,75139,75230 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74779 | michael.foord | 2009-09-13 11:13:36 -0500 (Sun, 13 Sep 2009) | 1 line
Change to tutorial wording for reading text / binary files on Windows. Issue #6301.
........
r74780 | michael.foord | 2009-09-13 11:40:02 -0500 (Sun, 13 Sep 2009) | 1 line
Objects that compare equal automatically pass or fail assertAlmostEqual and assertNotAlmostEqual tests on unittest.TestCase. Issue 6567.
........
r74781 | michael.foord | 2009-09-13 11:46:19 -0500 (Sun, 13 Sep 2009) | 1 line
Note that sys._getframe is not guaranteed to exist in all implementations of Python, and a corresponding note in inspect.currentframe. Issue 6712.
........
r74782 | michael.foord | 2009-09-13 12:07:46 -0500 (Sun, 13 Sep 2009) | 1 line
Tutorial tweaks. Issue 6849.
........
r74783 | michael.foord | 2009-09-13 12:28:35 -0500 (Sun, 13 Sep 2009) | 1 line
unittest.TestLoader.loadTestsFromName honors the loader suiteClass attribute. Issue 6866.
........
r74784 | georg.brandl | 2009-09-13 13:15:07 -0500 (Sun, 13 Sep 2009) | 1 line
Typo fix.
........
r74785 | michael.foord | 2009-09-13 14:07:03 -0500 (Sun, 13 Sep 2009) | 1 line
Test discovery in unittest will only attempt to import modules that are importable; i.e. their names are valid Python identifiers. If an import fails during discovery this will be recorded as an error and test discovery will continue. Issue 6568.
........
r74786 | michael.foord | 2009-09-13 14:08:18 -0500 (Sun, 13 Sep 2009) | 1 line
Remove an extraneous space in unittest documentation.
........
r74793 | georg.brandl | 2009-09-14 09:50:47 -0500 (Mon, 14 Sep 2009) | 1 line
#6908: fix association of hashlib hash attributes.
........
r74795 | benjamin.peterson | 2009-09-14 22:36:26 -0500 (Mon, 14 Sep 2009) | 1 line
Py_SetPythonHome uses static storage #6913
........
r74811 | georg.brandl | 2009-09-15 15:26:59 -0500 (Tue, 15 Sep 2009) | 1 line
Add Armin Ronacher.
........
r74860 | benjamin.peterson | 2009-09-16 21:46:54 -0500 (Wed, 16 Sep 2009) | 1 line
kill bare except
........
r74861 | benjamin.peterson | 2009-09-16 22:18:28 -0500 (Wed, 16 Sep 2009) | 1 line
pep 8 defaults
........
r74863 | benjamin.peterson | 2009-09-16 22:27:33 -0500 (Wed, 16 Sep 2009) | 1 line
rationalize a bit
........
r74876 | georg.brandl | 2009-09-17 11:15:53 -0500 (Thu, 17 Sep 2009) | 1 line
#6932: remove paragraph that advises relying on __del__ being called.
........
r74886 | benjamin.peterson | 2009-09-17 16:33:46 -0500 (Thu, 17 Sep 2009) | 1 line
use macros
........
r74896 | georg.brandl | 2009-09-18 02:22:41 -0500 (Fri, 18 Sep 2009) | 1 line
#6936: for interactive use, quit() is just fine.
........
r74901 | georg.brandl | 2009-09-18 04:14:52 -0500 (Fri, 18 Sep 2009) | 1 line
#6905: use better exception messages in inspect when the argument is of the wrong type.
........
r74903 | georg.brandl | 2009-09-18 04:18:27 -0500 (Fri, 18 Sep 2009) | 1 line
#6938: "ident" is always a string, so use a format code which works.
........
r74908 | georg.brandl | 2009-09-18 08:57:11 -0500 (Fri, 18 Sep 2009) | 1 line
Use str.format() to fix beginner's mistake with %-style string formatting.
........
r74912 | georg.brandl | 2009-09-18 11:19:56 -0500 (Fri, 18 Sep 2009) | 1 line
Optimize optimization and fix method name in docstring.
........
r74930 | georg.brandl | 2009-09-18 16:21:41 -0500 (Fri, 18 Sep 2009) | 1 line
#6925: rewrite docs for locals() and vars() a bit.
........
r74933 | georg.brandl | 2009-09-18 16:35:59 -0500 (Fri, 18 Sep 2009) | 1 line
#6930: clarify description about byteorder handling in UTF decoder routines.
........
r74943 | georg.brandl | 2009-09-19 02:35:07 -0500 (Sat, 19 Sep 2009) | 1 line
#6944: the argument to PyArg_ParseTuple should be a tuple, otherwise a SystemError is set. Also clean up another usage of PyArg_ParseTuple.
........
r74946 | georg.brandl | 2009-09-19 03:43:16 -0500 (Sat, 19 Sep 2009) | 1 line
Update bug tracker reference.
........
r74952 | georg.brandl | 2009-09-19 05:42:34 -0500 (Sat, 19 Sep 2009) | 1 line
#6946: fix duplicate index entries for datetime classes.
........
r74953 | georg.brandl | 2009-09-19 07:04:16 -0500 (Sat, 19 Sep 2009) | 1 line
Fix references to threading.enumerate().
........
r74954 | georg.brandl | 2009-09-19 08:13:56 -0500 (Sat, 19 Sep 2009) | 1 line
Add Doug.
........
r74955 | georg.brandl | 2009-09-19 08:20:49 -0500 (Sat, 19 Sep 2009) | 1 line
Add Mark Summerfield.
........
r75015 | georg.brandl | 2009-09-22 05:55:08 -0500 (Tue, 22 Sep 2009) | 1 line
Fix encoding name.
........
r75019 | vinay.sajip | 2009-09-22 12:23:41 -0500 (Tue, 22 Sep 2009) | 1 line
Fixed a typo, and added sections on optimization and using arbitrary objects as messages.
........
r75032 | benjamin.peterson | 2009-09-22 17:15:28 -0500 (Tue, 22 Sep 2009) | 1 line
fix typos/rephrase
........
r75068 | benjamin.peterson | 2009-09-25 21:57:59 -0500 (Fri, 25 Sep 2009) | 1 line
comment out ugly xxx
........
r75076 | vinay.sajip | 2009-09-26 09:53:32 -0500 (Sat, 26 Sep 2009) | 1 line
Tidied up name of parameter in StreamHandler
........
r75095 | michael.foord | 2009-09-27 14:15:41 -0500 (Sun, 27 Sep 2009) | 1 line
Test creation moved from TestProgram.parseArgs to TestProgram.createTests exclusively. Issue 6956.
........
r75098 | michael.foord | 2009-09-27 15:08:23 -0500 (Sun, 27 Sep 2009) | 1 line
Documentation improvement for load_tests protocol in unittest. Issue 6515.
........
r75102 | skip.montanaro | 2009-09-27 21:12:27 -0500 (Sun, 27 Sep 2009) | 3 lines
Patch from Thomas Barr so that csv.Sniffer will set doublequote property.
Closes issue 6606.
........
r75129 | vinay.sajip | 2009-09-29 02:08:54 -0500 (Tue, 29 Sep 2009) | 1 line
Issue #7014: logging: Improved IronPython 2.6 compatibility.
........
r75139 | raymond.hettinger | 2009-09-29 13:53:24 -0500 (Tue, 29 Sep 2009) | 3 lines
Issue 7008: Better document str.title and show how to work around the apostrophe problem.
........
r75230 | benjamin.peterson | 2009-10-04 08:38:38 -0500 (Sun, 04 Oct 2009) | 1 line
test logging
........
2009-10-04 11:49:41 -03:00
|
|
|
Free variables are returned by :func:`locals` when it is called in function
|
2019-04-02 14:58:50 -03:00
|
|
|
blocks, but not in class blocks. Note that at the module level, :func:`locals`
|
|
|
|
and :func:`globals` are the same dictionary.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2009-04-27 13:20:50 -03:00
|
|
|
.. note::
|
2009-05-17 10:00:36 -03:00
|
|
|
The contents of this dictionary should not be modified; changes may not
|
Merged revisions 74779-74786,74793,74795,74811,74860-74861,74863,74876,74886,74896,74901,74903,74908,74912,74930,74933,74943,74946,74952-74955,75015,75019,75032,75068,75076,75095,75098,75102,75129,75139,75230 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74779 | michael.foord | 2009-09-13 11:13:36 -0500 (Sun, 13 Sep 2009) | 1 line
Change to tutorial wording for reading text / binary files on Windows. Issue #6301.
........
r74780 | michael.foord | 2009-09-13 11:40:02 -0500 (Sun, 13 Sep 2009) | 1 line
Objects that compare equal automatically pass or fail assertAlmostEqual and assertNotAlmostEqual tests on unittest.TestCase. Issue 6567.
........
r74781 | michael.foord | 2009-09-13 11:46:19 -0500 (Sun, 13 Sep 2009) | 1 line
Note that sys._getframe is not guaranteed to exist in all implementations of Python, and a corresponding note in inspect.currentframe. Issue 6712.
........
r74782 | michael.foord | 2009-09-13 12:07:46 -0500 (Sun, 13 Sep 2009) | 1 line
Tutorial tweaks. Issue 6849.
........
r74783 | michael.foord | 2009-09-13 12:28:35 -0500 (Sun, 13 Sep 2009) | 1 line
unittest.TestLoader.loadTestsFromName honors the loader suiteClass attribute. Issue 6866.
........
r74784 | georg.brandl | 2009-09-13 13:15:07 -0500 (Sun, 13 Sep 2009) | 1 line
Typo fix.
........
r74785 | michael.foord | 2009-09-13 14:07:03 -0500 (Sun, 13 Sep 2009) | 1 line
Test discovery in unittest will only attempt to import modules that are importable; i.e. their names are valid Python identifiers. If an import fails during discovery this will be recorded as an error and test discovery will continue. Issue 6568.
........
r74786 | michael.foord | 2009-09-13 14:08:18 -0500 (Sun, 13 Sep 2009) | 1 line
Remove an extraneous space in unittest documentation.
........
r74793 | georg.brandl | 2009-09-14 09:50:47 -0500 (Mon, 14 Sep 2009) | 1 line
#6908: fix association of hashlib hash attributes.
........
r74795 | benjamin.peterson | 2009-09-14 22:36:26 -0500 (Mon, 14 Sep 2009) | 1 line
Py_SetPythonHome uses static storage #6913
........
r74811 | georg.brandl | 2009-09-15 15:26:59 -0500 (Tue, 15 Sep 2009) | 1 line
Add Armin Ronacher.
........
r74860 | benjamin.peterson | 2009-09-16 21:46:54 -0500 (Wed, 16 Sep 2009) | 1 line
kill bare except
........
r74861 | benjamin.peterson | 2009-09-16 22:18:28 -0500 (Wed, 16 Sep 2009) | 1 line
pep 8 defaults
........
r74863 | benjamin.peterson | 2009-09-16 22:27:33 -0500 (Wed, 16 Sep 2009) | 1 line
rationalize a bit
........
r74876 | georg.brandl | 2009-09-17 11:15:53 -0500 (Thu, 17 Sep 2009) | 1 line
#6932: remove paragraph that advises relying on __del__ being called.
........
r74886 | benjamin.peterson | 2009-09-17 16:33:46 -0500 (Thu, 17 Sep 2009) | 1 line
use macros
........
r74896 | georg.brandl | 2009-09-18 02:22:41 -0500 (Fri, 18 Sep 2009) | 1 line
#6936: for interactive use, quit() is just fine.
........
r74901 | georg.brandl | 2009-09-18 04:14:52 -0500 (Fri, 18 Sep 2009) | 1 line
#6905: use better exception messages in inspect when the argument is of the wrong type.
........
r74903 | georg.brandl | 2009-09-18 04:18:27 -0500 (Fri, 18 Sep 2009) | 1 line
#6938: "ident" is always a string, so use a format code which works.
........
r74908 | georg.brandl | 2009-09-18 08:57:11 -0500 (Fri, 18 Sep 2009) | 1 line
Use str.format() to fix beginner's mistake with %-style string formatting.
........
r74912 | georg.brandl | 2009-09-18 11:19:56 -0500 (Fri, 18 Sep 2009) | 1 line
Optimize optimization and fix method name in docstring.
........
r74930 | georg.brandl | 2009-09-18 16:21:41 -0500 (Fri, 18 Sep 2009) | 1 line
#6925: rewrite docs for locals() and vars() a bit.
........
r74933 | georg.brandl | 2009-09-18 16:35:59 -0500 (Fri, 18 Sep 2009) | 1 line
#6930: clarify description about byteorder handling in UTF decoder routines.
........
r74943 | georg.brandl | 2009-09-19 02:35:07 -0500 (Sat, 19 Sep 2009) | 1 line
#6944: the argument to PyArg_ParseTuple should be a tuple, otherwise a SystemError is set. Also clean up another usage of PyArg_ParseTuple.
........
r74946 | georg.brandl | 2009-09-19 03:43:16 -0500 (Sat, 19 Sep 2009) | 1 line
Update bug tracker reference.
........
r74952 | georg.brandl | 2009-09-19 05:42:34 -0500 (Sat, 19 Sep 2009) | 1 line
#6946: fix duplicate index entries for datetime classes.
........
r74953 | georg.brandl | 2009-09-19 07:04:16 -0500 (Sat, 19 Sep 2009) | 1 line
Fix references to threading.enumerate().
........
r74954 | georg.brandl | 2009-09-19 08:13:56 -0500 (Sat, 19 Sep 2009) | 1 line
Add Doug.
........
r74955 | georg.brandl | 2009-09-19 08:20:49 -0500 (Sat, 19 Sep 2009) | 1 line
Add Mark Summerfield.
........
r75015 | georg.brandl | 2009-09-22 05:55:08 -0500 (Tue, 22 Sep 2009) | 1 line
Fix encoding name.
........
r75019 | vinay.sajip | 2009-09-22 12:23:41 -0500 (Tue, 22 Sep 2009) | 1 line
Fixed a typo, and added sections on optimization and using arbitrary objects as messages.
........
r75032 | benjamin.peterson | 2009-09-22 17:15:28 -0500 (Tue, 22 Sep 2009) | 1 line
fix typos/rephrase
........
r75068 | benjamin.peterson | 2009-09-25 21:57:59 -0500 (Fri, 25 Sep 2009) | 1 line
comment out ugly xxx
........
r75076 | vinay.sajip | 2009-09-26 09:53:32 -0500 (Sat, 26 Sep 2009) | 1 line
Tidied up name of parameter in StreamHandler
........
r75095 | michael.foord | 2009-09-27 14:15:41 -0500 (Sun, 27 Sep 2009) | 1 line
Test creation moved from TestProgram.parseArgs to TestProgram.createTests exclusively. Issue 6956.
........
r75098 | michael.foord | 2009-09-27 15:08:23 -0500 (Sun, 27 Sep 2009) | 1 line
Documentation improvement for load_tests protocol in unittest. Issue 6515.
........
r75102 | skip.montanaro | 2009-09-27 21:12:27 -0500 (Sun, 27 Sep 2009) | 3 lines
Patch from Thomas Barr so that csv.Sniffer will set doublequote property.
Closes issue 6606.
........
r75129 | vinay.sajip | 2009-09-29 02:08:54 -0500 (Tue, 29 Sep 2009) | 1 line
Issue #7014: logging: Improved IronPython 2.6 compatibility.
........
r75139 | raymond.hettinger | 2009-09-29 13:53:24 -0500 (Tue, 29 Sep 2009) | 3 lines
Issue 7008: Better document str.title and show how to work around the apostrophe problem.
........
r75230 | benjamin.peterson | 2009-10-04 08:38:38 -0500 (Sun, 04 Oct 2009) | 1 line
test logging
........
2009-10-04 11:49:41 -03:00
|
|
|
affect the values of local and free variables used by the interpreter.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: map(function, iterable, *iterables)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2007-09-04 14:50:40 -03:00
|
|
|
Return an iterator that applies *function* to every item of *iterable*,
|
2022-10-15 07:19:35 -03:00
|
|
|
yielding the results. If additional *iterables* arguments are passed,
|
2007-09-04 14:50:40 -03:00
|
|
|
*function* must take that many arguments and is applied to the items from all
|
2008-05-05 18:04:12 -03:00
|
|
|
iterables in parallel. With multiple iterables, the iterator stops when the
|
2009-02-19 00:45:07 -04:00
|
|
|
shortest iterable is exhausted. For cases where the function inputs are
|
|
|
|
already arranged into argument tuples, see :func:`itertools.starmap`\.
|
2008-05-05 18:04:12 -03:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: max(iterable, *, key=None)
|
|
|
|
max(iterable, *, default, key=None)
|
|
|
|
max(arg1, arg2, *args, key=None)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-09-14 00:32:35 -03:00
|
|
|
Return the largest item in an iterable or the largest of two or more
|
|
|
|
arguments.
|
|
|
|
|
2013-06-25 02:43:02 -03:00
|
|
|
If one positional argument is provided, it should be an :term:`iterable`.
|
|
|
|
The largest item in the iterable is returned. If two or more positional
|
2014-04-03 12:01:22 -03:00
|
|
|
arguments are provided, the largest of the positional arguments is
|
2013-06-25 02:43:02 -03:00
|
|
|
returned.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2013-06-25 02:43:02 -03:00
|
|
|
There are two optional keyword-only arguments. The *key* argument specifies
|
|
|
|
a one-argument ordering function like that used for :meth:`list.sort`. The
|
|
|
|
*default* argument specifies an object to return if the provided iterable is
|
|
|
|
empty. If the iterable is empty and *default* is not provided, a
|
|
|
|
:exc:`ValueError` is raised.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-10-06 07:26:05 -03:00
|
|
|
If multiple items are maximal, the function returns the first one
|
|
|
|
encountered. This is consistent with other sort-stability preserving tools
|
|
|
|
such as ``sorted(iterable, key=keyfunc, reverse=True)[0]`` and
|
2010-09-14 20:13:42 -03:00
|
|
|
``heapq.nlargest(1, iterable, key=keyfunc)``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2014-03-16 01:13:56 -03:00
|
|
|
.. versionadded:: 3.4
|
|
|
|
The *default* keyword-only argument.
|
|
|
|
|
2018-07-24 00:58:21 -03:00
|
|
|
.. versionchanged:: 3.8
|
|
|
|
The *key* can be ``None``.
|
|
|
|
|
2011-09-01 18:08:55 -03:00
|
|
|
|
|
|
|
.. _func-memoryview:
|
2021-05-25 11:24:30 -03:00
|
|
|
.. class:: memoryview(object)
|
2008-09-10 18:02:02 -03:00
|
|
|
:noindex:
|
2007-08-31 13:33:38 -03:00
|
|
|
|
2008-09-09 19:15:27 -03:00
|
|
|
Return a "memory view" object created from the given argument. See
|
|
|
|
:ref:`typememoryview` for more information.
|
2007-08-31 13:33:38 -03:00
|
|
|
|
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: min(iterable, *, key=None)
|
|
|
|
min(iterable, *, default, key=None)
|
|
|
|
min(arg1, arg2, *args, key=None)
|
2012-09-14 00:32:35 -03:00
|
|
|
|
|
|
|
Return the smallest item in an iterable or the smallest of two or more
|
|
|
|
arguments.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2013-06-25 02:43:02 -03:00
|
|
|
If one positional argument is provided, it should be an :term:`iterable`.
|
|
|
|
The smallest item in the iterable is returned. If two or more positional
|
|
|
|
arguments are provided, the smallest of the positional arguments is
|
|
|
|
returned.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2013-06-25 02:43:02 -03:00
|
|
|
There are two optional keyword-only arguments. The *key* argument specifies
|
|
|
|
a one-argument ordering function like that used for :meth:`list.sort`. The
|
|
|
|
*default* argument specifies an object to return if the provided iterable is
|
|
|
|
empty. If the iterable is empty and *default* is not provided, a
|
|
|
|
:exc:`ValueError` is raised.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-10-06 07:26:05 -03:00
|
|
|
If multiple items are minimal, the function returns the first one
|
|
|
|
encountered. This is consistent with other sort-stability preserving tools
|
|
|
|
such as ``sorted(iterable, key=keyfunc)[0]`` and ``heapq.nsmallest(1,
|
|
|
|
iterable, key=keyfunc)``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2014-03-16 01:13:56 -03:00
|
|
|
.. versionadded:: 3.4
|
|
|
|
The *default* keyword-only argument.
|
|
|
|
|
2018-07-24 00:58:21 -03:00
|
|
|
.. versionchanged:: 3.8
|
|
|
|
The *key* can be ``None``.
|
|
|
|
|
2014-03-24 05:06:18 -03:00
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: next(iterator)
|
|
|
|
next(iterator, default)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2021-11-19 20:40:34 -04:00
|
|
|
Retrieve the next item from the :term:`iterator` by calling its
|
2012-10-12 07:42:08 -03:00
|
|
|
:meth:`~iterator.__next__` method. If *default* is given, it is returned
|
|
|
|
if the iterator is exhausted, otherwise :exc:`StopIteration` is raised.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2014-10-06 08:54:36 -03:00
|
|
|
.. class:: object()
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2007-08-31 13:33:38 -03:00
|
|
|
Return a new featureless object. :class:`object` is a base for all classes.
|
2021-07-19 13:02:23 -03:00
|
|
|
It has methods that are common to all instances of Python classes. This
|
2007-09-01 10:51:09 -03:00
|
|
|
function does not accept any arguments.
|
2007-08-31 13:33:38 -03:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
2013-10-09 08:02:31 -03:00
|
|
|
:class:`object` does *not* have a :attr:`~object.__dict__`, so you can't
|
|
|
|
assign arbitrary attributes to an instance of the :class:`object` class.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: oct(x)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-07-06 16:30:58 -03:00
|
|
|
Convert an integer number to an octal string prefixed with "0o". The result
|
|
|
|
is a valid Python expression. If *x* is not a Python :class:`int` object, it
|
2023-06-30 11:27:09 -03:00
|
|
|
has to define an :meth:`~object.__index__` method that returns an integer. For
|
2017-07-06 16:30:58 -03:00
|
|
|
example:
|
|
|
|
|
|
|
|
>>> oct(8)
|
|
|
|
'0o10'
|
|
|
|
>>> oct(-56)
|
|
|
|
'-0o70'
|
|
|
|
|
2021-07-19 13:02:23 -03:00
|
|
|
If you want to convert an integer number to an octal string either with the prefix
|
2017-07-06 16:30:58 -03:00
|
|
|
"0o" or not, you can use either of the following ways.
|
|
|
|
|
|
|
|
>>> '%#o' % 10, '%o' % 10
|
|
|
|
('0o12', '12')
|
|
|
|
>>> format(10, '#o'), format(10, 'o')
|
|
|
|
('0o12', '12')
|
|
|
|
>>> f'{10:#o}', f'{10:o}'
|
|
|
|
('0o12', '12')
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-07-06 16:30:58 -03:00
|
|
|
See also :func:`format` for more information.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-17 21:33:54 -03:00
|
|
|
.. index::
|
|
|
|
single: file object; open() built-in function
|
|
|
|
|
2011-10-31 15:34:46 -03:00
|
|
|
.. function:: open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-17 21:33:54 -03:00
|
|
|
Open *file* and return a corresponding :term:`file object`. If the file
|
2020-08-07 23:57:03 -03:00
|
|
|
cannot be opened, an :exc:`OSError` is raised. See
|
|
|
|
:ref:`tut-files` for more examples of how to use this function.
|
2009-01-03 17:18:54 -04:00
|
|
|
|
2016-09-06 19:55:02 -03:00
|
|
|
*file* is a :term:`path-like object` giving the pathname (absolute or
|
|
|
|
relative to the current working directory) of the file to be opened or an
|
|
|
|
integer file descriptor of the file to be wrapped. (If a file descriptor is
|
2021-07-19 13:02:23 -03:00
|
|
|
given, it is closed when the returned I/O object is closed unless *closefd*
|
2016-09-06 19:55:02 -03:00
|
|
|
is set to ``False``.)
|
2007-12-14 06:07:44 -04:00
|
|
|
|
|
|
|
*mode* is an optional string that specifies the mode in which the file is
|
2010-08-30 09:46:09 -03:00
|
|
|
opened. It defaults to ``'r'`` which means open for reading in text mode.
|
|
|
|
Other common values are ``'w'`` for writing (truncating the file if it
|
2021-07-19 13:02:23 -03:00
|
|
|
already exists), ``'x'`` for exclusive creation, and ``'a'`` for appending
|
2012-05-20 06:41:53 -03:00
|
|
|
(which on *some* Unix systems, means that *all* writes append to the end of
|
|
|
|
the file regardless of the current seek position). In text mode, if
|
2021-07-19 13:02:23 -03:00
|
|
|
*encoding* is not specified the encoding used is platform-dependent:
|
2022-04-21 22:39:24 -03:00
|
|
|
:func:`locale.getencoding()` is called to get the current locale encoding.
|
|
|
|
(For reading and writing raw bytes use binary mode and leave
|
2012-06-05 08:43:22 -03:00
|
|
|
*encoding* unspecified.) The available modes are:
|
2008-04-11 18:17:32 -03:00
|
|
|
|
2018-06-25 03:06:10 -03:00
|
|
|
.. _filemodes:
|
|
|
|
|
|
|
|
.. index::
|
|
|
|
pair: file; modes
|
|
|
|
|
2008-04-11 18:17:32 -03:00
|
|
|
========= ===============================================================
|
|
|
|
Character Meaning
|
2013-03-28 09:28:44 -03:00
|
|
|
========= ===============================================================
|
2008-04-11 18:17:32 -03:00
|
|
|
``'r'`` open for reading (default)
|
2010-08-30 09:46:09 -03:00
|
|
|
``'w'`` open for writing, truncating the file first
|
2012-05-20 06:41:53 -03:00
|
|
|
``'x'`` open for exclusive creation, failing if the file already exists
|
2021-07-19 13:02:23 -03:00
|
|
|
``'a'`` open for writing, appending to the end of file if it exists
|
2009-04-27 03:13:55 -03:00
|
|
|
``'b'`` binary mode
|
2010-08-30 09:46:09 -03:00
|
|
|
``'t'`` text mode (default)
|
2019-09-10 10:04:22 -03:00
|
|
|
``'+'`` open for updating (reading and writing)
|
2008-04-11 18:17:32 -03:00
|
|
|
========= ===============================================================
|
|
|
|
|
2021-07-19 13:02:23 -03:00
|
|
|
The default mode is ``'r'`` (open for reading text, a synonym of ``'rt'``).
|
2019-09-10 11:48:05 -03:00
|
|
|
Modes ``'w+'`` and ``'w+b'`` open and truncate the file. Modes ``'r+'``
|
|
|
|
and ``'r+b'`` open the file with no truncation.
|
2010-08-30 09:46:09 -03:00
|
|
|
|
2010-08-30 10:19:53 -03:00
|
|
|
As mentioned in the :ref:`io-overview`, Python distinguishes between binary
|
|
|
|
and text I/O. Files opened in binary mode (including ``'b'`` in the *mode*
|
|
|
|
argument) return contents as :class:`bytes` objects without any decoding. In
|
|
|
|
text mode (the default, or when ``'t'`` is included in the *mode* argument),
|
|
|
|
the contents of the file are returned as :class:`str`, the bytes having been
|
|
|
|
first decoded using a platform-dependent encoding or using the specified
|
|
|
|
*encoding* if given.
|
2010-08-30 09:46:09 -03:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
2010-08-30 10:19:53 -03:00
|
|
|
Python doesn't depend on the underlying operating system's notion of text
|
2011-10-19 04:58:56 -03:00
|
|
|
files; all the processing is done by Python itself, and is therefore
|
2010-08-30 10:19:53 -03:00
|
|
|
platform-independent.
|
2010-08-30 09:46:09 -03:00
|
|
|
|
2010-08-30 10:19:53 -03:00
|
|
|
*buffering* is an optional integer used to set the buffering policy. Pass 0
|
|
|
|
to switch buffering off (only allowed in binary mode), 1 to select line
|
|
|
|
buffering (only usable in text mode), and an integer > 1 to indicate the size
|
2022-04-20 05:24:53 -03:00
|
|
|
in bytes of a fixed-size chunk buffer. Note that specifying a buffer size this
|
|
|
|
way applies for binary buffered I/O, but ``TextIOWrapper`` (i.e., files opened
|
|
|
|
with ``mode='r+'``) would have another buffering. To disable buffering in
|
|
|
|
``TextIOWrapper``, consider using the ``write_through`` flag for
|
|
|
|
:func:`io.TextIOWrapper.reconfigure`. When no *buffering* argument is
|
2013-03-16 16:56:27 -03:00
|
|
|
given, the default buffering policy works as follows:
|
2010-08-30 09:46:09 -03:00
|
|
|
|
2010-08-30 10:19:53 -03:00
|
|
|
* Binary files are buffered in fixed-size chunks; the size of the buffer is
|
|
|
|
chosen using a heuristic trying to determine the underlying device's "block
|
|
|
|
size" and falling back on :attr:`io.DEFAULT_BUFFER_SIZE`. On many systems,
|
|
|
|
the buffer will typically be 4096 or 8192 bytes long.
|
|
|
|
|
2013-10-09 08:02:31 -03:00
|
|
|
* "Interactive" text files (files for which :meth:`~io.IOBase.isatty`
|
2013-11-29 06:17:13 -04:00
|
|
|
returns ``True``) use line buffering. Other text files use the policy
|
2013-10-09 08:02:31 -03:00
|
|
|
described above for binary files.
|
2009-01-03 17:18:54 -04:00
|
|
|
|
2008-04-11 18:17:32 -03:00
|
|
|
*encoding* is the name of the encoding used to decode or encode the file.
|
|
|
|
This should only be used in text mode. The default encoding is platform
|
2022-04-21 22:39:24 -03:00
|
|
|
dependent (whatever :func:`locale.getencoding` returns), but any
|
|
|
|
:term:`text encoding` supported by Python can be used.
|
|
|
|
See the :mod:`codecs` module for the list of supported encodings.
|
2009-03-22 23:44:58 -03:00
|
|
|
|
|
|
|
*errors* is an optional string that specifies how encoding and decoding
|
2016-11-20 20:15:20 -04:00
|
|
|
errors are to be handled—this cannot be used in binary mode.
|
2015-01-06 10:22:00 -04:00
|
|
|
A variety of standard error handlers are available
|
|
|
|
(listed under :ref:`error-handlers`), though any
|
2013-06-16 13:58:48 -03:00
|
|
|
error handling name that has been registered with
|
|
|
|
:func:`codecs.register_error` is also valid. The standard names
|
2015-01-06 10:22:00 -04:00
|
|
|
include:
|
2013-06-16 13:58:48 -03:00
|
|
|
|
|
|
|
* ``'strict'`` to raise a :exc:`ValueError` exception if there is
|
|
|
|
an encoding error. The default value of ``None`` has the same
|
|
|
|
effect.
|
|
|
|
|
|
|
|
* ``'ignore'`` ignores errors. Note that ignoring encoding errors
|
|
|
|
can lead to data loss.
|
|
|
|
|
|
|
|
* ``'replace'`` causes a replacement marker (such as ``'?'``) to be inserted
|
|
|
|
where there is malformed data.
|
|
|
|
|
2021-08-09 11:14:54 -03:00
|
|
|
* ``'surrogateescape'`` will represent any incorrect bytes as low
|
|
|
|
surrogate code units ranging from U+DC80 to U+DCFF.
|
|
|
|
These surrogate code units will then be turned back into
|
2013-06-16 13:58:48 -03:00
|
|
|
the same bytes when the ``surrogateescape`` error handler is used
|
|
|
|
when writing data. This is useful for processing files in an
|
|
|
|
unknown encoding.
|
|
|
|
|
|
|
|
* ``'xmlcharrefreplace'`` is only supported when writing to a file.
|
|
|
|
Characters not supported by the encoding are replaced with the
|
|
|
|
appropriate XML character reference ``&#nnn;``.
|
|
|
|
|
2015-01-25 16:56:57 -04:00
|
|
|
* ``'backslashreplace'`` replaces malformed data by Python's backslashed
|
|
|
|
escape sequences.
|
2008-04-11 18:17:32 -03:00
|
|
|
|
2014-11-25 07:57:17 -04:00
|
|
|
* ``'namereplace'`` (also only supported when writing)
|
|
|
|
replaces unsupported characters with ``\N{...}`` escape sequences.
|
|
|
|
|
2012-08-15 11:43:58 -03:00
|
|
|
.. index::
|
|
|
|
single: universal newlines; open() built-in function
|
|
|
|
|
2019-01-27 12:21:11 -04:00
|
|
|
.. _open-newline-parameter:
|
|
|
|
|
2022-10-07 15:12:08 -03:00
|
|
|
*newline* determines how to parse newline characters from the stream.
|
|
|
|
It can be ``None``, ``''``, ``'\n'``, ``'\r'``, and
|
2012-08-15 12:05:36 -03:00
|
|
|
``'\r\n'``. It works as follows:
|
2008-04-11 18:17:32 -03:00
|
|
|
|
2012-08-14 04:39:07 -03:00
|
|
|
* When reading input from the stream, if *newline* is ``None``, universal
|
|
|
|
newlines mode is enabled. Lines in the input can end in ``'\n'``,
|
|
|
|
``'\r'``, or ``'\r\n'``, and these are translated into ``'\n'`` before
|
2012-08-15 11:43:58 -03:00
|
|
|
being returned to the caller. If it is ``''``, universal newlines mode is
|
2012-08-14 04:39:07 -03:00
|
|
|
enabled, but line endings are returned to the caller untranslated. If it
|
|
|
|
has any of the other legal values, input lines are only terminated by the
|
|
|
|
given string, and the line ending is returned to the caller untranslated.
|
|
|
|
|
|
|
|
* When writing output to the stream, if *newline* is ``None``, any ``'\n'``
|
|
|
|
characters written are translated to the system default line separator,
|
|
|
|
:data:`os.linesep`. If *newline* is ``''`` or ``'\n'``, no translation
|
|
|
|
takes place. If *newline* is any of the other legal values, any ``'\n'``
|
|
|
|
characters written are translated to the given string.
|
2008-04-11 18:17:32 -03:00
|
|
|
|
2009-03-22 23:38:01 -03:00
|
|
|
If *closefd* is ``False`` and a file descriptor rather than a filename was
|
|
|
|
given, the underlying file descriptor will be kept open when the file is
|
2021-07-19 13:02:23 -03:00
|
|
|
closed. If a filename is given *closefd* must be ``True`` (the default);
|
|
|
|
otherwise, an error will be raised.
|
2009-03-22 23:38:01 -03:00
|
|
|
|
2011-10-31 15:34:46 -03:00
|
|
|
A custom opener can be used by passing a callable as *opener*. The underlying
|
|
|
|
file descriptor for the file object is then obtained by calling *opener* with
|
|
|
|
(*file*, *flags*). *opener* must return an open file descriptor (passing
|
|
|
|
:mod:`os.open` as *opener* results in functionality similar to passing
|
|
|
|
``None``).
|
|
|
|
|
2013-08-27 19:53:59 -03:00
|
|
|
The newly created file is :ref:`non-inheritable <fd_inheritance>`.
|
|
|
|
|
2012-11-22 01:13:49 -04:00
|
|
|
The following example uses the :ref:`dir_fd <dir_fd>` parameter of the
|
2012-11-03 18:06:52 -03:00
|
|
|
:func:`os.open` function to open a file relative to a given directory::
|
|
|
|
|
|
|
|
>>> import os
|
2012-11-22 01:13:49 -04:00
|
|
|
>>> dir_fd = os.open('somedir', os.O_RDONLY)
|
|
|
|
>>> def opener(path, flags):
|
|
|
|
... return os.open(path, flags, dir_fd=dir_fd)
|
2012-11-03 18:06:52 -03:00
|
|
|
...
|
|
|
|
>>> with open('spamspam.txt', 'w', opener=opener) as f:
|
|
|
|
... print('This will be written to somedir/spamspam.txt', file=f)
|
|
|
|
...
|
2012-11-03 18:39:45 -03:00
|
|
|
>>> os.close(dir_fd) # don't leak a file descriptor
|
2012-11-03 18:06:52 -03:00
|
|
|
|
2012-08-17 21:33:54 -03:00
|
|
|
The type of :term:`file object` returned by the :func:`open` function
|
2012-08-17 21:39:21 -03:00
|
|
|
depends on the mode. When :func:`open` is used to open a file in a text
|
|
|
|
mode (``'w'``, ``'r'``, ``'wt'``, ``'rt'``, etc.), it returns a subclass of
|
2010-08-30 10:19:53 -03:00
|
|
|
:class:`io.TextIOBase` (specifically :class:`io.TextIOWrapper`). When used
|
|
|
|
to open a file in a binary mode with buffering, the returned class is a
|
|
|
|
subclass of :class:`io.BufferedIOBase`. The exact class varies: in read
|
2015-11-01 23:37:02 -04:00
|
|
|
binary mode, it returns an :class:`io.BufferedReader`; in write binary and
|
|
|
|
append binary modes, it returns an :class:`io.BufferedWriter`, and in
|
|
|
|
read/write mode, it returns an :class:`io.BufferedRandom`. When buffering is
|
2010-08-30 10:19:53 -03:00
|
|
|
disabled, the raw stream, a subclass of :class:`io.RawIOBase`,
|
|
|
|
:class:`io.FileIO`, is returned.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. index::
|
|
|
|
single: line-buffered I/O
|
|
|
|
single: unbuffered I/O
|
|
|
|
single: buffer size, I/O
|
|
|
|
single: I/O control; buffering
|
2007-09-23 18:13:45 -03:00
|
|
|
single: binary mode
|
|
|
|
single: text mode
|
2023-05-04 05:17:12 -03:00
|
|
|
pair: module; sys
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2021-07-19 13:02:23 -03:00
|
|
|
See also the file handling modules, such as :mod:`fileinput`, :mod:`io`
|
2009-03-22 23:38:01 -03:00
|
|
|
(where :func:`open` is declared), :mod:`os`, :mod:`os.path`, :mod:`tempfile`,
|
|
|
|
and :mod:`shutil`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2019-06-27 14:47:59 -03:00
|
|
|
.. audit-event:: open file,mode,flags open
|
2019-05-23 12:45:22 -03:00
|
|
|
|
|
|
|
The ``mode`` and ``flags`` arguments may have been modified or inferred from
|
|
|
|
the original call.
|
|
|
|
|
2021-09-02 07:58:00 -03:00
|
|
|
.. versionchanged:: 3.3
|
2011-10-12 15:10:51 -03:00
|
|
|
|
2016-08-31 01:22:36 -03:00
|
|
|
* The *opener* parameter was added.
|
|
|
|
* The ``'x'`` mode was added.
|
|
|
|
* :exc:`IOError` used to be raised, it is now an alias of :exc:`OSError`.
|
|
|
|
* :exc:`FileExistsError` is now raised if the file opened in exclusive
|
2017-03-24 23:55:08 -03:00
|
|
|
creation mode (``'x'``) already exists.
|
2016-08-31 01:22:36 -03:00
|
|
|
|
2021-09-02 07:58:00 -03:00
|
|
|
.. versionchanged:: 3.4
|
2016-08-31 01:22:36 -03:00
|
|
|
|
|
|
|
* The file is now non-inheritable.
|
2013-08-27 19:53:59 -03:00
|
|
|
|
2021-09-02 07:58:00 -03:00
|
|
|
.. versionchanged:: 3.5
|
2015-03-26 19:50:57 -03:00
|
|
|
|
2016-08-31 01:22:36 -03:00
|
|
|
* If the system call is interrupted and the signal handler does not raise an
|
|
|
|
exception, the function now retries the system call instead of raising an
|
|
|
|
:exc:`InterruptedError` exception (see :pep:`475` for the rationale).
|
|
|
|
* The ``'namereplace'`` error handler was added.
|
|
|
|
|
2021-09-02 07:58:00 -03:00
|
|
|
.. versionchanged:: 3.6
|
2008-02-01 07:56:49 -04:00
|
|
|
|
2016-08-31 01:22:36 -03:00
|
|
|
* Support added to accept objects implementing :class:`os.PathLike`.
|
|
|
|
* On Windows, opening a console buffer may return a subclass of
|
|
|
|
:class:`io.RawIOBase` other than :class:`io.FileIO`.
|
2016-06-09 19:58:06 -03:00
|
|
|
|
2021-09-02 07:58:00 -03:00
|
|
|
.. versionchanged:: 3.11
|
|
|
|
The ``'U'`` mode has been removed.
|
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: ord(c)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-10-25 03:32:34 -03:00
|
|
|
Given a string representing one Unicode character, return an integer
|
2014-08-17 01:07:53 -03:00
|
|
|
representing the Unicode code point of that character. For example,
|
2016-03-20 22:18:40 -03:00
|
|
|
``ord('a')`` returns the integer ``97`` and ``ord('€')`` (Euro sign)
|
|
|
|
returns ``8364``. This is the inverse of :func:`chr`.
|
2008-02-01 07:56:49 -04:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-10-15 07:19:35 -03:00
|
|
|
.. function:: pow(base, exp, mod=None)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2019-09-21 01:28:49 -03:00
|
|
|
Return *base* to the power *exp*; if *mod* is present, return *base* to the
|
|
|
|
power *exp*, modulo *mod* (computed more efficiently than
|
|
|
|
``pow(base, exp) % mod``). The two-argument form ``pow(base, exp)`` is
|
|
|
|
equivalent to using the power operator: ``base**exp``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-05-05 18:42:51 -03:00
|
|
|
The arguments must have numeric types. With mixed operand types, the
|
|
|
|
coercion rules for binary arithmetic operators apply. For :class:`int`
|
|
|
|
operands, the result has the same type as the operands (after coercion)
|
|
|
|
unless the second argument is negative; in that case, all arguments are
|
2021-09-28 17:40:57 -03:00
|
|
|
converted to float and a float result is delivered. For example, ``pow(10, 2)``
|
2021-10-21 17:57:49 -03:00
|
|
|
returns ``100``, but ``pow(10, -2)`` returns ``0.01``. For a negative base of
|
|
|
|
type :class:`int` or :class:`float` and a non-integral exponent, a complex
|
|
|
|
result is delivered. For example, ``pow(-9, 0.5)`` returns a value close
|
|
|
|
to ``3j``.
|
2019-06-02 06:24:06 -03:00
|
|
|
|
2019-09-21 01:28:49 -03:00
|
|
|
For :class:`int` operands *base* and *exp*, if *mod* is present, *mod* must
|
|
|
|
also be of integer type and *mod* must be nonzero. If *mod* is present and
|
|
|
|
*exp* is negative, *base* must be relatively prime to *mod*. In that case,
|
|
|
|
``pow(inv_base, -exp, mod)`` is returned, where *inv_base* is an inverse to
|
|
|
|
*base* modulo *mod*.
|
2019-06-02 06:24:06 -03:00
|
|
|
|
|
|
|
Here's an example of computing an inverse for ``38`` modulo ``97``::
|
|
|
|
|
2019-09-21 01:28:49 -03:00
|
|
|
>>> pow(38, -1, mod=97)
|
2019-06-02 06:24:06 -03:00
|
|
|
23
|
|
|
|
>>> 23 * 38 % 97 == 1
|
|
|
|
True
|
|
|
|
|
|
|
|
.. versionchanged:: 3.8
|
|
|
|
For :class:`int` operands, the three-argument form of ``pow`` now allows
|
|
|
|
the second argument to be negative, permitting computation of modular
|
|
|
|
inverses.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2020-03-19 15:12:59 -03:00
|
|
|
.. versionchanged:: 3.8
|
2019-09-21 01:28:49 -03:00
|
|
|
Allow keyword arguments. Formerly, only positional arguments were
|
|
|
|
supported.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-11-06 16:14:58 -04:00
|
|
|
.. function:: print(*objects, sep=' ', end='\n', file=None, flush=False)
|
2008-02-01 07:56:49 -04:00
|
|
|
|
2014-10-01 16:37:42 -03:00
|
|
|
Print *objects* to the text stream *file*, separated by *sep* and followed
|
2021-07-19 13:02:23 -03:00
|
|
|
by *end*. *sep*, *end*, *file*, and *flush*, if present, must be given as keyword
|
2008-02-01 07:56:49 -04:00
|
|
|
arguments.
|
|
|
|
|
|
|
|
All non-keyword arguments are converted to strings like :func:`str` does and
|
|
|
|
written to the stream, separated by *sep* and followed by *end*. Both *sep*
|
|
|
|
and *end* must be strings; they can also be ``None``, which means to use the
|
2012-09-14 00:32:35 -03:00
|
|
|
default values. If no *objects* are given, :func:`print` will just write
|
2008-02-01 07:56:49 -04:00
|
|
|
*end*.
|
|
|
|
|
|
|
|
The *file* argument must be an object with a ``write(string)`` method; if it
|
2014-10-01 16:37:42 -03:00
|
|
|
is not present or ``None``, :data:`sys.stdout` will be used. Since printed
|
|
|
|
arguments are converted to text strings, :func:`print` cannot be used with
|
|
|
|
binary mode file objects. For these, use ``file.write(...)`` instead.
|
|
|
|
|
2023-04-05 08:16:36 -03:00
|
|
|
Output buffering is usually determined by *file*.
|
|
|
|
However, if *flush* is true, the stream is forcibly flushed.
|
|
|
|
|
2012-01-13 14:41:25 -04:00
|
|
|
|
|
|
|
.. versionchanged:: 3.3
|
|
|
|
Added the *flush* keyword argument.
|
2008-02-01 07:56:49 -04:00
|
|
|
|
|
|
|
|
2014-10-06 08:54:36 -03:00
|
|
|
.. class:: property(fget=None, fset=None, fdel=None, doc=None)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2007-08-31 13:33:38 -03:00
|
|
|
Return a property attribute.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2014-08-10 14:41:25 -03:00
|
|
|
*fget* is a function for getting an attribute value. *fset* is a function
|
|
|
|
for setting an attribute value. *fdel* is a function for deleting an attribute
|
|
|
|
value. And *doc* creates a docstring for the attribute.
|
|
|
|
|
|
|
|
A typical use is to define a managed attribute ``x``::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-11-21 23:09:19 -04:00
|
|
|
class C:
|
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
|
|
|
def __init__(self):
|
|
|
|
self._x = None
|
|
|
|
|
|
|
|
def getx(self):
|
|
|
|
return self._x
|
2014-08-10 14:41:25 -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
|
|
|
def setx(self, value):
|
|
|
|
self._x = value
|
2014-08-10 14:41:25 -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
|
|
|
def delx(self):
|
|
|
|
del self._x
|
2014-08-10 14:41:25 -03:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
x = property(getx, setx, delx, "I'm the 'x' property.")
|
|
|
|
|
2014-08-10 14:41:25 -03:00
|
|
|
If *c* is an instance of *C*, ``c.x`` will invoke the getter,
|
2021-07-19 13:02:23 -03:00
|
|
|
``c.x = value`` will invoke the setter, and ``del c.x`` the deleter.
|
2010-08-02 16:23:34 -03:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
If given, *doc* will be the docstring of the property attribute. Otherwise, the
|
|
|
|
property will copy *fget*'s docstring (if it exists). This makes it possible to
|
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
|
|
|
create read-only properties easily using :func:`property` as a :term:`decorator`::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-11-21 23:09:19 -04:00
|
|
|
class Parrot:
|
2007-08-15 11:28:22 -03:00
|
|
|
def __init__(self):
|
|
|
|
self._voltage = 100000
|
|
|
|
|
|
|
|
@property
|
|
|
|
def voltage(self):
|
|
|
|
"""Get the current voltage."""
|
|
|
|
return self._voltage
|
|
|
|
|
2014-08-10 14:41:25 -03:00
|
|
|
The ``@property`` decorator turns the :meth:`voltage` method into a "getter"
|
|
|
|
for a read-only attribute with the same name, and it sets the docstring for
|
|
|
|
*voltage* to "Get the current voltage."
|
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
|
|
|
|
2013-10-09 08:02:31 -03:00
|
|
|
A property object has :attr:`~property.getter`, :attr:`~property.setter`,
|
|
|
|
and :attr:`~property.deleter` methods usable as decorators that create a
|
|
|
|
copy of the property with the corresponding accessor function set to the
|
|
|
|
decorated function. This is best explained with an example::
|
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
|
|
|
|
2010-11-21 23:09:19 -04:00
|
|
|
class C:
|
Merged revisions 66887,66891,66902-66903,66905-66906,66911-66913,66922,66927-66928,66936,66939-66940,66962,66964,66973 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r66887 | benjamin.peterson | 2008-10-13 16:51:40 -0500 (Mon, 13 Oct 2008) | 1 line
document how to disable fixers
................
r66891 | amaury.forgeotdarc | 2008-10-14 16:47:22 -0500 (Tue, 14 Oct 2008) | 5 lines
#4122: On Windows, Py_UNICODE_ISSPACE cannot be used in an extension module:
compilation fails with "undefined reference to _Py_ascii_whitespace"
Will backport to 2.6.
................
r66902 | skip.montanaro | 2008-10-15 06:49:10 -0500 (Wed, 15 Oct 2008) | 1 line
easter egg
................
r66903 | benjamin.peterson | 2008-10-15 15:34:09 -0500 (Wed, 15 Oct 2008) | 1 line
don't recurse into directories that start with '.'
................
r66905 | benjamin.peterson | 2008-10-15 16:05:55 -0500 (Wed, 15 Oct 2008) | 1 line
support the optional line argument for idle
................
r66906 | benjamin.peterson | 2008-10-15 16:58:46 -0500 (Wed, 15 Oct 2008) | 1 line
add a much requested newline
................
r66911 | benjamin.peterson | 2008-10-15 18:10:28 -0500 (Wed, 15 Oct 2008) | 41 lines
Merged revisions 66805,66841,66860,66884-66886,66893,66907,66910 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r66805 | benjamin.peterson | 2008-10-04 20:11:02 -0500 (Sat, 04 Oct 2008) | 1 line
mention what the fixes directory is for
........
r66841 | benjamin.peterson | 2008-10-07 17:48:12 -0500 (Tue, 07 Oct 2008) | 1 line
use assertFalse and assertTrue
........
r66860 | benjamin.peterson | 2008-10-08 16:05:07 -0500 (Wed, 08 Oct 2008) | 1 line
instead of abusing the pattern matcher, use start_tree to find a next binding
........
r66884 | benjamin.peterson | 2008-10-13 15:50:30 -0500 (Mon, 13 Oct 2008) | 1 line
don't print tokens to stdout when -v is given
........
r66885 | benjamin.peterson | 2008-10-13 16:28:57 -0500 (Mon, 13 Oct 2008) | 1 line
add the -x option to disable fixers
........
r66886 | benjamin.peterson | 2008-10-13 16:33:53 -0500 (Mon, 13 Oct 2008) | 1 line
cut down on some crud
........
r66893 | benjamin.peterson | 2008-10-14 17:16:54 -0500 (Tue, 14 Oct 2008) | 1 line
add an optional set literal fixer
........
r66907 | benjamin.peterson | 2008-10-15 16:59:41 -0500 (Wed, 15 Oct 2008) | 1 line
don't write backup files by default
........
r66910 | benjamin.peterson | 2008-10-15 17:43:10 -0500 (Wed, 15 Oct 2008) | 1 line
add the -n option; it stops backupfiles from being written
........
................
r66912 | hirokazu.yamamoto | 2008-10-16 01:25:25 -0500 (Thu, 16 Oct 2008) | 2 lines
removed unused _PyUnicode_FromFileSystemEncodedObject.
made win32_chdir, win32_wchdir static.
................
r66913 | benjamin.peterson | 2008-10-16 13:52:14 -0500 (Thu, 16 Oct 2008) | 1 line
document that deque indexing is O(n) #4123
................
r66922 | benjamin.peterson | 2008-10-16 14:40:14 -0500 (Thu, 16 Oct 2008) | 1 line
use new showwarnings signature for idle #3391
................
r66927 | andrew.kuchling | 2008-10-16 15:15:47 -0500 (Thu, 16 Oct 2008) | 1 line
Fix wording (2.6.1 backport candidate)
................
r66928 | georg.brandl | 2008-10-16 15:20:56 -0500 (Thu, 16 Oct 2008) | 2 lines
Add more TOC to the whatsnew index page.
................
r66936 | georg.brandl | 2008-10-16 16:20:15 -0500 (Thu, 16 Oct 2008) | 2 lines
#4131: FF3 doesn't write cookies.txt files.
................
r66939 | georg.brandl | 2008-10-16 16:36:39 -0500 (Thu, 16 Oct 2008) | 2 lines
part of #4012: kill off old name "processing".
................
r66940 | georg.brandl | 2008-10-16 16:38:48 -0500 (Thu, 16 Oct 2008) | 2 lines
#4083: add "as" to except handler grammar as per PEP 3110.
................
r66962 | benjamin.peterson | 2008-10-17 15:01:01 -0500 (Fri, 17 Oct 2008) | 1 line
clarify CALL_FUNCTION #4141
................
r66964 | georg.brandl | 2008-10-17 16:41:49 -0500 (Fri, 17 Oct 2008) | 2 lines
Fix duplicate word.
................
r66973 | armin.ronacher | 2008-10-19 03:27:43 -0500 (Sun, 19 Oct 2008) | 3 lines
Fixed #4067 by implementing _attributes and _fields for the AST root node.
................
2008-10-19 11:07:49 -03:00
|
|
|
def __init__(self):
|
|
|
|
self._x = None
|
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
|
|
|
|
|
|
|
@property
|
|
|
|
def x(self):
|
|
|
|
"""I'm the 'x' property."""
|
|
|
|
return self._x
|
|
|
|
|
|
|
|
@x.setter
|
|
|
|
def x(self, value):
|
|
|
|
self._x = value
|
|
|
|
|
|
|
|
@x.deleter
|
|
|
|
def x(self):
|
|
|
|
del self._x
|
|
|
|
|
|
|
|
This code is exactly equivalent to the first example. Be sure to give the
|
|
|
|
additional functions the same name as the original property (``x`` in this
|
|
|
|
case.)
|
|
|
|
|
2014-08-10 14:41:25 -03:00
|
|
|
The returned property object also has the attributes ``fget``, ``fset``, and
|
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
|
|
|
``fdel`` corresponding to the constructor arguments.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2015-05-15 20:17:05 -03:00
|
|
|
.. versionchanged:: 3.5
|
|
|
|
The docstrings of property objects are now writeable.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
.. _func-range:
|
2022-11-19 06:25:45 -04:00
|
|
|
.. class:: range(stop)
|
|
|
|
range(start, stop, step=1)
|
2012-08-21 04:42:52 -03:00
|
|
|
:noindex:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
Rather than being a function, :class:`range` is actually an immutable
|
2012-10-13 00:28:26 -03:00
|
|
|
sequence type, as documented in :ref:`typesseq-range` and :ref:`typesseq`.
|
2011-11-05 16:17:52 -03:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: repr(object)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-03-25 04:21:32 -03:00
|
|
|
Return a string containing a printable representation of an object. For many
|
|
|
|
types, this function makes an attempt to return a string that would yield an
|
2021-07-19 13:02:23 -03:00
|
|
|
object with the same value when passed to :func:`eval`; otherwise, the
|
2008-03-25 04:21:32 -03:00
|
|
|
representation is a string enclosed in angle brackets that contains the name
|
|
|
|
of the type of the object together with additional information often
|
|
|
|
including the name and address of the object. A class can control what this
|
|
|
|
function returns for its instances by defining a :meth:`__repr__` method.
|
2022-08-25 23:02:57 -03:00
|
|
|
If :func:`sys.displayhook` is not accessible, this function will raise
|
|
|
|
:exc:`RuntimeError`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: reversed(seq)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
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
|
|
|
Return a reverse :term:`iterator`. *seq* must be an object which has
|
|
|
|
a :meth:`__reversed__` method or supports the sequence protocol (the
|
|
|
|
:meth:`__len__` method and the :meth:`__getitem__` method with integer
|
|
|
|
arguments starting at ``0``).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2022-10-15 07:19:35 -03:00
|
|
|
.. function:: round(number, ndigits=None)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-03-29 18:14:06 -03:00
|
|
|
Return *number* rounded to *ndigits* precision after the decimal
|
|
|
|
point. If *ndigits* is omitted or is ``None``, it returns the
|
|
|
|
nearest integer to its input.
|
2008-07-01 17:39:59 -03:00
|
|
|
|
|
|
|
For the built-in types supporting :func:`round`, values are rounded to the
|
2012-09-20 16:51:14 -03:00
|
|
|
closest multiple of 10 to the power minus *ndigits*; if two multiples are
|
|
|
|
equally close, rounding is done toward the even choice (so, for example,
|
|
|
|
both ``round(0.5)`` and ``round(-0.5)`` are ``0``, and ``round(1.5)`` is
|
2017-03-27 19:15:20 -03:00
|
|
|
``2``). Any integer value is valid for *ndigits* (positive, zero, or
|
2018-05-20 12:00:18 -03:00
|
|
|
negative). The return value is an integer if *ndigits* is omitted or
|
|
|
|
``None``.
|
2021-07-19 13:02:23 -03:00
|
|
|
Otherwise, the return value has the same type as *number*.
|
Merged revisions 59666-59679 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59666 | christian.heimes | 2008-01-02 19:28:32 +0100 (Wed, 02 Jan 2008) | 1 line
Made vs9to8 Unix compatible
........
r59669 | guido.van.rossum | 2008-01-02 20:00:46 +0100 (Wed, 02 Jan 2008) | 2 lines
Patch #1696. Don't attempt to close None in dry-run mode.
........
r59671 | jeffrey.yasskin | 2008-01-03 03:21:52 +0100 (Thu, 03 Jan 2008) | 6 lines
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
the complex_pow part), r56649, r56652, r56715, r57296, r57302, r57359, r57361,
r57372, r57738, r57739, r58017, r58039, r58040, and r59390, and new
documentation. The only significant difference is that round(x) returns a float
to preserve backward-compatibility. See http://bugs.python.org/issue1689.
........
r59672 | christian.heimes | 2008-01-03 16:41:30 +0100 (Thu, 03 Jan 2008) | 1 line
Issue #1726: Remove Python/atof.c from PCBuild/pythoncore.vcproj
........
r59675 | guido.van.rossum | 2008-01-03 20:12:44 +0100 (Thu, 03 Jan 2008) | 4 lines
Issue #1700, reported by Nguyen Quan Son, fix by Fredruk Lundh:
Regular Expression inline flags not handled correctly for some unicode
characters. (Forward port from 2.5.2.)
........
r59676 | christian.heimes | 2008-01-03 21:23:15 +0100 (Thu, 03 Jan 2008) | 1 line
Added math.isinf() and math.isnan()
........
r59677 | christian.heimes | 2008-01-03 22:14:48 +0100 (Thu, 03 Jan 2008) | 1 line
Some build bots don't compile mathmodule. There is an issue with the long definition of pi and euler
........
r59678 | christian.heimes | 2008-01-03 23:16:32 +0100 (Thu, 03 Jan 2008) | 2 lines
Modified PyImport_Import and PyImport_ImportModule to always use absolute imports by calling __import__ with an explicit level of 0
Added a new API function PyImport_ImportModuleNoBlock. It solves the problem with dead locks when mixing threads and imports
........
r59679 | christian.heimes | 2008-01-03 23:32:26 +0100 (Thu, 03 Jan 2008) | 1 line
Added copysign(x, y) function to the math module
........
2008-01-03 19:01:04 -04:00
|
|
|
|
2018-05-20 12:00:18 -03:00
|
|
|
For a general Python object ``number``, ``round`` delegates to
|
|
|
|
``number.__round__``.
|
2017-03-29 18:14:06 -03:00
|
|
|
|
2010-07-30 10:13:02 -03:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
The behavior of :func:`round` for floats can be surprising: for example,
|
|
|
|
``round(2.675, 2)`` gives ``2.67`` instead of the expected ``2.68``.
|
|
|
|
This is not a bug: it's a result of the fact that most decimal fractions
|
|
|
|
can't be represented exactly as a float. See :ref:`tut-fp-issues` for
|
|
|
|
more information.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-09-01 18:08:55 -03:00
|
|
|
|
|
|
|
.. _func-set:
|
2022-10-15 07:19:35 -03:00
|
|
|
.. class:: set()
|
2022-11-19 06:25:45 -04:00
|
|
|
set(iterable)
|
2007-08-15 11:28:22 -03:00
|
|
|
:noindex:
|
|
|
|
|
2012-11-09 22:57:32 -04:00
|
|
|
Return a new :class:`set` object, optionally with elements taken from
|
|
|
|
*iterable*. ``set`` is a built-in class. See :class:`set` and
|
|
|
|
:ref:`types-set` for documentation about this class.
|
|
|
|
|
|
|
|
For other containers see the built-in :class:`frozenset`, :class:`list`,
|
|
|
|
:class:`tuple`, and :class:`dict` classes, as well as the :mod:`collections`
|
|
|
|
module.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. function:: setattr(object, name, value)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
This is the counterpart of :func:`getattr`. The arguments are an object, a
|
2021-07-19 13:02:23 -03:00
|
|
|
string, and an arbitrary value. The string may name an existing attribute or a
|
2007-08-15 11:28:22 -03:00
|
|
|
new attribute. The function assigns the value to the attribute, provided the
|
|
|
|
object allows it. For example, ``setattr(x, 'foobar', 123)`` is equivalent to
|
|
|
|
``x.foobar = 123``.
|
|
|
|
|
2022-09-29 20:02:27 -03:00
|
|
|
*name* need not be a Python identifier as defined in :ref:`identifiers`
|
|
|
|
unless the object chooses to enforce that, for example in a custom
|
|
|
|
:meth:`~object.__getattribute__` or via :attr:`~object.__slots__`.
|
|
|
|
An attribute whose name is not an identifier will not be accessible using
|
|
|
|
the dot notation, but is accessible through :func:`getattr` etc..
|
|
|
|
|
2021-02-02 17:06:57 -04:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
Since :ref:`private name mangling <private-name-mangling>` happens at
|
|
|
|
compilation time, one must manually mangle a private attribute's
|
|
|
|
(attributes with two leading underscores) name in order to set it with
|
|
|
|
:func:`setattr`.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. class:: slice(stop)
|
|
|
|
slice(start, stop, step=1)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
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
|
|
|
Return a :term:`slice` object representing the set of indices specified by
|
2007-08-15 11:28:22 -03:00
|
|
|
``range(start, stop, step)``. The *start* and *step* arguments default to
|
2013-10-09 08:02:31 -03:00
|
|
|
``None``. Slice objects have read-only data attributes :attr:`~slice.start`,
|
2021-07-19 13:02:23 -03:00
|
|
|
:attr:`~slice.stop`, and :attr:`~slice.step` which merely return the argument
|
2013-10-09 08:02:31 -03:00
|
|
|
values (or their default). They have no other explicit functionality;
|
2021-07-19 13:02:23 -03:00
|
|
|
however, they are used by NumPy and other third-party packages.
|
2013-10-09 08:02:31 -03:00
|
|
|
Slice objects are also generated when extended indexing syntax is used. For
|
|
|
|
example: ``a[start:stop:step]`` or ``a[start:stop, i]``. See
|
|
|
|
:func:`itertools.islice` for an alternate version that returns an iterator.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2023-02-18 20:22:02 -04:00
|
|
|
.. versionchanged:: 3.12
|
|
|
|
Slice objects are now :term:`hashable` (provided :attr:`~slice.start`,
|
|
|
|
:attr:`~slice.stop`, and :attr:`~slice.step` are hashable).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2021-12-15 07:24:38 -04:00
|
|
|
.. function:: sorted(iterable, /, *, key=None, reverse=False)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Return a new sorted list from the items in *iterable*.
|
|
|
|
|
2008-02-14 09:52:24 -04:00
|
|
|
Has two optional arguments which must be specified as keyword arguments.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
*key* specifies a function of one argument that is used to extract a comparison
|
2018-10-15 16:06:53 -03:00
|
|
|
key from each element in *iterable* (for example, ``key=str.lower``). The
|
|
|
|
default value is ``None`` (compare the elements directly).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
*reverse* is a boolean value. If set to ``True``, then the list elements are
|
|
|
|
sorted as if each comparison were reversed.
|
|
|
|
|
2010-08-17 14:52:02 -03:00
|
|
|
Use :func:`functools.cmp_to_key` to convert an old-style *cmp* function to a
|
|
|
|
*key* function.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2014-10-28 08:57:11 -03:00
|
|
|
The built-in :func:`sorted` function 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).
|
|
|
|
|
2021-09-21 14:26:27 -03:00
|
|
|
The sort algorithm uses only ``<`` comparisons between items. While
|
|
|
|
defining an :meth:`~object.__lt__` method will suffice for sorting,
|
|
|
|
:PEP:`8` recommends that all six :ref:`rich comparisons
|
|
|
|
<comparisons>` be implemented. This will help avoid bugs when using
|
|
|
|
the same data with other ordering tools such as :func:`max` that rely
|
|
|
|
on a different underlying method. Implementing all six comparisons
|
|
|
|
also helps avoid confusion for mixed type comparisons which can call
|
|
|
|
reflected the :meth:`~object.__gt__` method.
|
|
|
|
|
2016-01-02 03:25:58 -04:00
|
|
|
For sorting examples and a brief sorting tutorial, see :ref:`sortinghowto`.
|
2010-04-01 21:25:45 -03:00
|
|
|
|
2017-10-12 11:39:43 -03:00
|
|
|
.. decorator:: staticmethod
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-10-12 11:39:43 -03:00
|
|
|
Transform a method into a static method.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
A static method does not receive an implicit first argument. To declare a static
|
|
|
|
method, use this idiom::
|
|
|
|
|
|
|
|
class C:
|
|
|
|
@staticmethod
|
2023-04-11 10:50:25 -03:00
|
|
|
def f(arg1, arg2, argN): ...
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2019-03-25 19:53:43 -03:00
|
|
|
The ``@staticmethod`` form is a function :term:`decorator` -- see
|
|
|
|
:ref:`function` for details.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2021-04-11 19:21:22 -03:00
|
|
|
A static method can be called either on the class (such as ``C.f()``) or on
|
|
|
|
an instance (such as ``C().f()``). Moreover, they can be called as regular
|
|
|
|
functions (such as ``f()``).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2021-07-19 13:02:23 -03:00
|
|
|
Static methods in Python are similar to those found in Java or C++. Also, see
|
2011-06-01 20:17:23 -03:00
|
|
|
:func:`classmethod` for a variant that is useful for creating alternate class
|
|
|
|
constructors.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-10-12 13:28:55 -03:00
|
|
|
Like all decorators, it is also possible to call ``staticmethod`` as
|
|
|
|
a regular function and do something with its result. This is needed
|
|
|
|
in some cases where you need a reference to a function from a class
|
|
|
|
body and you want to avoid the automatic transformation to instance
|
2018-01-29 04:30:48 -04:00
|
|
|
method. For these cases, use this idiom::
|
2017-10-12 13:28:55 -03:00
|
|
|
|
2021-04-11 19:21:22 -03:00
|
|
|
def regular_function():
|
|
|
|
...
|
|
|
|
|
2017-10-12 13:28:55 -03:00
|
|
|
class C:
|
2021-04-11 19:21:22 -03:00
|
|
|
method = staticmethod(regular_function)
|
2017-10-12 13:28:55 -03:00
|
|
|
|
2019-03-25 19:53:43 -03:00
|
|
|
For more information on static methods, see :ref:`types`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2021-04-09 12:51:22 -03:00
|
|
|
.. versionchanged:: 3.10
|
|
|
|
Static methods now inherit the method attributes (``__module__``,
|
2021-04-11 19:21:22 -03:00
|
|
|
``__name__``, ``__qualname__``, ``__doc__`` and ``__annotations__``),
|
|
|
|
have a new ``__wrapped__`` attribute, and are now callable as regular
|
|
|
|
functions.
|
2021-04-09 12:51:22 -03:00
|
|
|
|
2012-11-20 21:45:51 -04:00
|
|
|
|
2017-10-12 13:28:55 -03:00
|
|
|
.. index::
|
|
|
|
single: string; str() (built-in function)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
.. _func-str:
|
2014-10-06 08:54:36 -03:00
|
|
|
.. class:: str(object='')
|
|
|
|
str(object=b'', encoding='utf-8', errors='strict')
|
2012-11-28 05:38:40 -04:00
|
|
|
:noindex:
|
2012-11-20 21:45:51 -04:00
|
|
|
|
2012-11-28 05:38:40 -04:00
|
|
|
Return a :class:`str` version of *object*. See :func:`str` for details.
|
2012-11-20 21:45:51 -04:00
|
|
|
|
2012-11-28 05:38:40 -04:00
|
|
|
``str`` is the built-in string :term:`class`. For general information
|
|
|
|
about strings, see :ref:`textseq`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2019-06-05 20:11:46 -03:00
|
|
|
.. function:: sum(iterable, /, start=0)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Sums *start* and the items of an *iterable* from left to right and returns the
|
2019-06-05 20:11:46 -03:00
|
|
|
total. The *iterable*'s items are normally numbers, and the start value is not
|
|
|
|
allowed to be a string.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-11-06 03:30:16 -03:00
|
|
|
For some use cases, there are good alternatives to :func:`sum`.
|
2010-10-31 18:23:24 -03:00
|
|
|
The preferred, fast way to concatenate a sequence of strings is by calling
|
|
|
|
``''.join(sequence)``. To add floating point values with extended precision,
|
|
|
|
see :func:`math.fsum`\. To concatenate a series of iterables, consider using
|
|
|
|
:func:`itertools.chain`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2018-09-12 14:54:06 -03:00
|
|
|
.. versionchanged:: 3.8
|
|
|
|
The *start* parameter can be specified as a keyword argument.
|
|
|
|
|
2022-12-23 18:35:58 -04:00
|
|
|
.. versionchanged:: 3.12 Summation of floats switched to an algorithm
|
|
|
|
that gives higher accuracy on most builds.
|
|
|
|
|
|
|
|
|
2022-10-15 07:19:35 -03:00
|
|
|
.. class:: super()
|
2022-11-19 06:25:45 -04:00
|
|
|
super(type, object_or_type=None)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2009-02-24 19:30:43 -04:00
|
|
|
Return a proxy object that delegates method calls to a parent or sibling
|
|
|
|
class of *type*. This is useful for accessing inherited methods that have
|
2019-08-29 04:44:02 -03:00
|
|
|
been overridden in a class.
|
2009-02-24 19:30:43 -04:00
|
|
|
|
2022-10-15 07:19:35 -03:00
|
|
|
The *object_or_type* determines the :term:`method resolution order`
|
2019-08-29 04:44:02 -03:00
|
|
|
to be searched. The search starts from the class right after the
|
|
|
|
*type*.
|
|
|
|
|
2022-10-15 07:19:35 -03:00
|
|
|
For example, if :attr:`~class.__mro__` of *object_or_type* is
|
2019-08-29 04:44:02 -03:00
|
|
|
``D -> B -> C -> A -> object`` and the value of *type* is ``B``,
|
|
|
|
then :func:`super` searches ``C -> A -> object``.
|
|
|
|
|
2022-10-15 07:19:35 -03:00
|
|
|
The :attr:`~class.__mro__` attribute of the *object_or_type* lists the method
|
2013-10-09 08:02:31 -03:00
|
|
|
resolution search order used by both :func:`getattr` and :func:`super`. The
|
|
|
|
attribute is dynamic and can change whenever the inheritance hierarchy is
|
|
|
|
updated.
|
Merged revisions 66045,66048-66049,66053,66060,66062-66063,66065,66067,66071-66074,66080,66082-66083,66090-66093,66097-66099,66103,66105,66110,66118 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r66045 | andrew.kuchling | 2008-08-26 19:27:18 -0500 (Tue, 26 Aug 2008) | 1 line
Trim whitespace; add a few updates
........
r66048 | andrew.kuchling | 2008-08-26 19:45:02 -0500 (Tue, 26 Aug 2008) | 1 line
Add an item and a note
........
r66049 | andrew.kuchling | 2008-08-26 21:12:18 -0500 (Tue, 26 Aug 2008) | 1 line
Add various items
........
r66053 | georg.brandl | 2008-08-28 04:40:18 -0500 (Thu, 28 Aug 2008) | 2 lines
#3711: .dll isn't a valid Python extension anymore.
........
r66060 | armin.rigo | 2008-08-29 16:21:52 -0500 (Fri, 29 Aug 2008) | 3 lines
A collection of crashers, all variants of the idea
of issue #3720.
........
r66062 | georg.brandl | 2008-08-30 04:49:36 -0500 (Sat, 30 Aug 2008) | 2 lines
#3730: mention "server" attribute explicitly.
........
r66063 | georg.brandl | 2008-08-30 04:52:44 -0500 (Sat, 30 Aug 2008) | 2 lines
#3716: fix typo.
........
r66065 | georg.brandl | 2008-08-30 05:03:09 -0500 (Sat, 30 Aug 2008) | 2 lines
#3569: eval() also accepts "exec"able code objects.
........
r66067 | georg.brandl | 2008-08-30 08:17:39 -0500 (Sat, 30 Aug 2008) | 2 lines
super() actually returns a super object.
........
r66071 | andrew.kuchling | 2008-08-30 10:19:57 -0500 (Sat, 30 Aug 2008) | 1 line
Partial edits from revision and tidying pass
........
r66072 | andrew.kuchling | 2008-08-30 10:21:23 -0500 (Sat, 30 Aug 2008) | 1 line
Tidy up some sentences
........
r66073 | andrew.kuchling | 2008-08-30 10:25:47 -0500 (Sat, 30 Aug 2008) | 1 line
Correction from Antoine Pitrou: BufferedWriter and Reader support seek()
........
r66074 | andrew.kuchling | 2008-08-30 11:44:54 -0500 (Sat, 30 Aug 2008) | 1 line
Edit four more sections
........
r66080 | georg.brandl | 2008-08-30 17:00:28 -0500 (Sat, 30 Aug 2008) | 2 lines
Fix markup.
........
r66082 | andrew.kuchling | 2008-08-30 17:56:54 -0500 (Sat, 30 Aug 2008) | 1 line
More edits; markup fixes
........
r66083 | andrew.kuchling | 2008-08-30 21:24:08 -0500 (Sat, 30 Aug 2008) | 1 line
More edits
........
r66090 | andrew.kuchling | 2008-08-31 09:29:31 -0500 (Sun, 31 Aug 2008) | 1 line
Edit the library section, rearranging items to flow better and making lots of edits
........
r66091 | andrew.kuchling | 2008-08-31 10:41:48 -0500 (Sun, 31 Aug 2008) | 1 line
Last batch of edits; remove the 'other changes' section
........
r66092 | andrew.kuchling | 2008-08-31 10:48:44 -0500 (Sun, 31 Aug 2008) | 1 line
Update patch/bug count
........
r66093 | gregory.p.smith | 2008-08-31 11:34:18 -0500 (Sun, 31 Aug 2008) | 3 lines
issue3715: docstring representation of hex escaped string needs to be double
escaped.
........
r66097 | benjamin.peterson | 2008-09-01 09:13:43 -0500 (Mon, 01 Sep 2008) | 4 lines
#3703 unhelpful _fileio.FileIO error message when trying to open a directory
Reviewer: Gregory P. Smith
........
r66098 | georg.brandl | 2008-09-01 09:15:55 -0500 (Mon, 01 Sep 2008) | 2 lines
#3749: fix c'n'p errors.
........
r66099 | benjamin.peterson | 2008-09-01 09:18:30 -0500 (Mon, 01 Sep 2008) | 4 lines
Fix compilation when --without-threads is given #3683
Reviewer: Georg Brandl, Benjamin Peterson
........
r66103 | vinay.sajip | 2008-09-01 09:30:10 -0500 (Mon, 01 Sep 2008) | 1 line
logging: fixed lack of use of encoding attribute specified on a stream.
........
r66105 | vinay.sajip | 2008-09-01 09:33:59 -0500 (Mon, 01 Sep 2008) | 1 line
logging: fixed lack of use of encoding attribute specified on a stream.
........
r66110 | vinay.sajip | 2008-09-01 10:08:07 -0500 (Mon, 01 Sep 2008) | 1 line
Added section about configuring logging in a library. Thanks to Thomas Heller for the idea.
........
r66118 | vinay.sajip | 2008-09-01 12:44:14 -0500 (Mon, 01 Sep 2008) | 1 line
Bug #3738: Documentation is now more accurate in describing handler close methods.
........
2008-09-01 21:31:15 -03:00
|
|
|
|
2009-02-24 20:32:51 -04:00
|
|
|
If the second argument is omitted, the super object returned is unbound. If
|
Merged revisions 66508,66510,66512-66513,66523-66526,66529-66530,66532,66535,66538,66544,66546 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r66508 | benjamin.peterson | 2008-09-18 18:20:28 -0500 (Thu, 18 Sep 2008) | 1 line
tabify
........
r66510 | josiah.carlson | 2008-09-18 21:07:22 -0500 (Thu, 18 Sep 2008) | 2 lines
Fix for documentation bug. Fixes issue 3904.
........
r66512 | raymond.hettinger | 2008-09-19 03:07:48 -0500 (Fri, 19 Sep 2008) | 1 line
Improve docs for super().
........
r66513 | lars.gustaebel | 2008-09-19 07:39:23 -0500 (Fri, 19 Sep 2008) | 2 lines
Correct information about the tarfile module.
........
r66523 | georg.brandl | 2008-09-21 02:14:44 -0500 (Sun, 21 Sep 2008) | 2 lines
#3852: fix some select.kqueue and kevent docs.
........
r66524 | georg.brandl | 2008-09-21 02:15:59 -0500 (Sun, 21 Sep 2008) | 2 lines
#3912: document default for *places* arg.
........
r66525 | georg.brandl | 2008-09-21 02:17:00 -0500 (Sun, 21 Sep 2008) | 2 lines
#3916: fixes for docs wrt. Windows directory layout
........
r66526 | georg.brandl | 2008-09-21 02:18:28 -0500 (Sun, 21 Sep 2008) | 2 lines
#3914: add //= to the augmented assign operators.
........
r66529 | georg.brandl | 2008-09-21 02:24:11 -0500 (Sun, 21 Sep 2008) | 2 lines
#3901: bsddb fix.
........
r66530 | georg.brandl | 2008-09-21 02:31:52 -0500 (Sun, 21 Sep 2008) | 2 lines
#3897: _collections now has an underscore.
........
r66532 | georg.brandl | 2008-09-21 02:36:22 -0500 (Sun, 21 Sep 2008) | 2 lines
Update readme and Makefile (web builder doesn't exist).
........
r66535 | georg.brandl | 2008-09-21 03:03:21 -0500 (Sun, 21 Sep 2008) | 2 lines
#3918: note that uniform() args can be swapped.
........
r66538 | georg.brandl | 2008-09-21 05:03:39 -0500 (Sun, 21 Sep 2008) | 2 lines
Add "dist" target.
........
r66544 | benjamin.peterson | 2008-09-21 16:27:51 -0500 (Sun, 21 Sep 2008) | 4 lines
#3879 fix a regression in urllib.getproxies_environment
reviewers: Benjamin, Georg
........
r66546 | georg.brandl | 2008-09-21 17:31:59 -0500 (Sun, 21 Sep 2008) | 2 lines
Fill out download page.
........
2008-09-22 19:10:59 -03:00
|
|
|
the second argument is an object, ``isinstance(obj, type)`` must be true. If
|
Merged revisions 69576,69579-69580,69589,69619-69620,69633,69703-69704,69728-69730 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r69576 | georg.brandl | 2009-02-13 04:56:50 -0600 (Fri, 13 Feb 2009) | 1 line
#1661108: note that urlsafe encoded string can contain "=".
........
r69579 | georg.brandl | 2009-02-13 05:06:59 -0600 (Fri, 13 Feb 2009) | 2 lines
Fix warnings GCC emits where the argument of PyErr_Format is a single variable.
........
r69580 | georg.brandl | 2009-02-13 05:10:04 -0600 (Fri, 13 Feb 2009) | 2 lines
Fix warnings GCC emits where the argument of PyErr_Format is a single variable.
........
r69589 | martin.v.loewis | 2009-02-13 14:11:34 -0600 (Fri, 13 Feb 2009) | 2 lines
Move amd64 properties further to the top, so that they override
the linker options correctly.
........
r69619 | benjamin.peterson | 2009-02-14 11:00:51 -0600 (Sat, 14 Feb 2009) | 1 line
this needn't be a shebang line
........
r69620 | georg.brandl | 2009-02-14 11:01:36 -0600 (Sat, 14 Feb 2009) | 1 line
#5179: don't leak PIPE fds when child execution fails.
........
r69633 | hirokazu.yamamoto | 2009-02-15 03:19:48 -0600 (Sun, 15 Feb 2009) | 1 line
Fixed typo.
........
r69703 | raymond.hettinger | 2009-02-16 16:42:54 -0600 (Mon, 16 Feb 2009) | 3 lines
Issue 5229: Documentation for super() neglects to say what super() actually does
........
r69704 | raymond.hettinger | 2009-02-16 17:00:25 -0600 (Mon, 16 Feb 2009) | 1 line
Add explanation for super(type1, type2).
........
r69728 | georg.brandl | 2009-02-17 18:22:55 -0600 (Tue, 17 Feb 2009) | 2 lines
#5297: fix example.
........
r69729 | georg.brandl | 2009-02-17 18:25:13 -0600 (Tue, 17 Feb 2009) | 2 lines
#5296: sequence -> iterable.
........
r69730 | georg.brandl | 2009-02-17 18:31:36 -0600 (Tue, 17 Feb 2009) | 2 lines
#5268: mention VMSError.
........
2009-02-19 00:22:03 -04:00
|
|
|
the second argument is a type, ``issubclass(type2, type)`` must be true (this
|
|
|
|
is useful for classmethods).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2009-02-24 20:58:47 -04:00
|
|
|
There are two typical use cases for *super*. In a class hierarchy with
|
|
|
|
single inheritance, *super* can be used to refer to parent classes without
|
Merged revisions 66508,66510,66512-66513,66523-66526,66529-66530,66532,66535,66538,66544,66546 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r66508 | benjamin.peterson | 2008-09-18 18:20:28 -0500 (Thu, 18 Sep 2008) | 1 line
tabify
........
r66510 | josiah.carlson | 2008-09-18 21:07:22 -0500 (Thu, 18 Sep 2008) | 2 lines
Fix for documentation bug. Fixes issue 3904.
........
r66512 | raymond.hettinger | 2008-09-19 03:07:48 -0500 (Fri, 19 Sep 2008) | 1 line
Improve docs for super().
........
r66513 | lars.gustaebel | 2008-09-19 07:39:23 -0500 (Fri, 19 Sep 2008) | 2 lines
Correct information about the tarfile module.
........
r66523 | georg.brandl | 2008-09-21 02:14:44 -0500 (Sun, 21 Sep 2008) | 2 lines
#3852: fix some select.kqueue and kevent docs.
........
r66524 | georg.brandl | 2008-09-21 02:15:59 -0500 (Sun, 21 Sep 2008) | 2 lines
#3912: document default for *places* arg.
........
r66525 | georg.brandl | 2008-09-21 02:17:00 -0500 (Sun, 21 Sep 2008) | 2 lines
#3916: fixes for docs wrt. Windows directory layout
........
r66526 | georg.brandl | 2008-09-21 02:18:28 -0500 (Sun, 21 Sep 2008) | 2 lines
#3914: add //= to the augmented assign operators.
........
r66529 | georg.brandl | 2008-09-21 02:24:11 -0500 (Sun, 21 Sep 2008) | 2 lines
#3901: bsddb fix.
........
r66530 | georg.brandl | 2008-09-21 02:31:52 -0500 (Sun, 21 Sep 2008) | 2 lines
#3897: _collections now has an underscore.
........
r66532 | georg.brandl | 2008-09-21 02:36:22 -0500 (Sun, 21 Sep 2008) | 2 lines
Update readme and Makefile (web builder doesn't exist).
........
r66535 | georg.brandl | 2008-09-21 03:03:21 -0500 (Sun, 21 Sep 2008) | 2 lines
#3918: note that uniform() args can be swapped.
........
r66538 | georg.brandl | 2008-09-21 05:03:39 -0500 (Sun, 21 Sep 2008) | 2 lines
Add "dist" target.
........
r66544 | benjamin.peterson | 2008-09-21 16:27:51 -0500 (Sun, 21 Sep 2008) | 4 lines
#3879 fix a regression in urllib.getproxies_environment
reviewers: Benjamin, Georg
........
r66546 | georg.brandl | 2008-09-21 17:31:59 -0500 (Sun, 21 Sep 2008) | 2 lines
Fill out download page.
........
2008-09-22 19:10:59 -03:00
|
|
|
naming them explicitly, thus making the code more maintainable. This use
|
2009-02-24 20:58:47 -04:00
|
|
|
closely parallels the use of *super* in other programming languages.
|
2009-01-03 17:18:54 -04:00
|
|
|
|
2009-02-24 19:30:43 -04:00
|
|
|
The second use case is to support cooperative multiple inheritance in a
|
2009-01-03 17:18:54 -04:00
|
|
|
dynamic execution environment. This use case is unique to Python and is
|
|
|
|
not found in statically compiled languages or languages that only support
|
2009-02-25 20:27:18 -04:00
|
|
|
single inheritance. This makes it possible to implement "diamond diagrams"
|
Merged revisions 66508,66510,66512-66513,66523-66526,66529-66530,66532,66535,66538,66544,66546 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r66508 | benjamin.peterson | 2008-09-18 18:20:28 -0500 (Thu, 18 Sep 2008) | 1 line
tabify
........
r66510 | josiah.carlson | 2008-09-18 21:07:22 -0500 (Thu, 18 Sep 2008) | 2 lines
Fix for documentation bug. Fixes issue 3904.
........
r66512 | raymond.hettinger | 2008-09-19 03:07:48 -0500 (Fri, 19 Sep 2008) | 1 line
Improve docs for super().
........
r66513 | lars.gustaebel | 2008-09-19 07:39:23 -0500 (Fri, 19 Sep 2008) | 2 lines
Correct information about the tarfile module.
........
r66523 | georg.brandl | 2008-09-21 02:14:44 -0500 (Sun, 21 Sep 2008) | 2 lines
#3852: fix some select.kqueue and kevent docs.
........
r66524 | georg.brandl | 2008-09-21 02:15:59 -0500 (Sun, 21 Sep 2008) | 2 lines
#3912: document default for *places* arg.
........
r66525 | georg.brandl | 2008-09-21 02:17:00 -0500 (Sun, 21 Sep 2008) | 2 lines
#3916: fixes for docs wrt. Windows directory layout
........
r66526 | georg.brandl | 2008-09-21 02:18:28 -0500 (Sun, 21 Sep 2008) | 2 lines
#3914: add //= to the augmented assign operators.
........
r66529 | georg.brandl | 2008-09-21 02:24:11 -0500 (Sun, 21 Sep 2008) | 2 lines
#3901: bsddb fix.
........
r66530 | georg.brandl | 2008-09-21 02:31:52 -0500 (Sun, 21 Sep 2008) | 2 lines
#3897: _collections now has an underscore.
........
r66532 | georg.brandl | 2008-09-21 02:36:22 -0500 (Sun, 21 Sep 2008) | 2 lines
Update readme and Makefile (web builder doesn't exist).
........
r66535 | georg.brandl | 2008-09-21 03:03:21 -0500 (Sun, 21 Sep 2008) | 2 lines
#3918: note that uniform() args can be swapped.
........
r66538 | georg.brandl | 2008-09-21 05:03:39 -0500 (Sun, 21 Sep 2008) | 2 lines
Add "dist" target.
........
r66544 | benjamin.peterson | 2008-09-21 16:27:51 -0500 (Sun, 21 Sep 2008) | 4 lines
#3879 fix a regression in urllib.getproxies_environment
reviewers: Benjamin, Georg
........
r66546 | georg.brandl | 2008-09-21 17:31:59 -0500 (Sun, 21 Sep 2008) | 2 lines
Fill out download page.
........
2008-09-22 19:10:59 -03:00
|
|
|
where multiple base classes implement the same method. Good design dictates
|
2021-04-28 22:12:15 -03:00
|
|
|
that such implementations have the same calling signature in every case (because the
|
2009-02-24 19:30:43 -04:00
|
|
|
order of calls is determined at runtime, because that order adapts
|
|
|
|
to changes in the class hierarchy, and because that order can include
|
|
|
|
sibling classes that are unknown prior to runtime).
|
Merged revisions 66508,66510,66512-66513,66523-66526,66529-66530,66532,66535,66538,66544,66546 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r66508 | benjamin.peterson | 2008-09-18 18:20:28 -0500 (Thu, 18 Sep 2008) | 1 line
tabify
........
r66510 | josiah.carlson | 2008-09-18 21:07:22 -0500 (Thu, 18 Sep 2008) | 2 lines
Fix for documentation bug. Fixes issue 3904.
........
r66512 | raymond.hettinger | 2008-09-19 03:07:48 -0500 (Fri, 19 Sep 2008) | 1 line
Improve docs for super().
........
r66513 | lars.gustaebel | 2008-09-19 07:39:23 -0500 (Fri, 19 Sep 2008) | 2 lines
Correct information about the tarfile module.
........
r66523 | georg.brandl | 2008-09-21 02:14:44 -0500 (Sun, 21 Sep 2008) | 2 lines
#3852: fix some select.kqueue and kevent docs.
........
r66524 | georg.brandl | 2008-09-21 02:15:59 -0500 (Sun, 21 Sep 2008) | 2 lines
#3912: document default for *places* arg.
........
r66525 | georg.brandl | 2008-09-21 02:17:00 -0500 (Sun, 21 Sep 2008) | 2 lines
#3916: fixes for docs wrt. Windows directory layout
........
r66526 | georg.brandl | 2008-09-21 02:18:28 -0500 (Sun, 21 Sep 2008) | 2 lines
#3914: add //= to the augmented assign operators.
........
r66529 | georg.brandl | 2008-09-21 02:24:11 -0500 (Sun, 21 Sep 2008) | 2 lines
#3901: bsddb fix.
........
r66530 | georg.brandl | 2008-09-21 02:31:52 -0500 (Sun, 21 Sep 2008) | 2 lines
#3897: _collections now has an underscore.
........
r66532 | georg.brandl | 2008-09-21 02:36:22 -0500 (Sun, 21 Sep 2008) | 2 lines
Update readme and Makefile (web builder doesn't exist).
........
r66535 | georg.brandl | 2008-09-21 03:03:21 -0500 (Sun, 21 Sep 2008) | 2 lines
#3918: note that uniform() args can be swapped.
........
r66538 | georg.brandl | 2008-09-21 05:03:39 -0500 (Sun, 21 Sep 2008) | 2 lines
Add "dist" target.
........
r66544 | benjamin.peterson | 2008-09-21 16:27:51 -0500 (Sun, 21 Sep 2008) | 4 lines
#3879 fix a regression in urllib.getproxies_environment
reviewers: Benjamin, Georg
........
r66546 | georg.brandl | 2008-09-21 17:31:59 -0500 (Sun, 21 Sep 2008) | 2 lines
Fill out download page.
........
2008-09-22 19:10:59 -03:00
|
|
|
|
|
|
|
For both use cases, a typical superclass call looks like this::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
class C(B):
|
2008-02-26 09:27:00 -04:00
|
|
|
def method(self, arg):
|
2009-05-17 10:00:36 -03:00
|
|
|
super().method(arg) # This does the same thing as:
|
|
|
|
# super(C, self).method(arg)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2019-09-25 12:13:19 -03:00
|
|
|
In addition to method lookups, :func:`super` also works for attribute
|
2019-11-20 22:10:19 -04:00
|
|
|
lookups. One possible use case for this is calling :term:`descriptors <descriptor>`
|
2019-09-25 12:13:19 -03:00
|
|
|
in a parent or sibling class.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
Note that :func:`super` is implemented as part of the binding process for
|
2008-02-26 09:27:00 -04:00
|
|
|
explicit dotted attribute lookups such as ``super().__getitem__(name)``.
|
Merged revisions 66508,66510,66512-66513,66523-66526,66529-66530,66532,66535,66538,66544,66546 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r66508 | benjamin.peterson | 2008-09-18 18:20:28 -0500 (Thu, 18 Sep 2008) | 1 line
tabify
........
r66510 | josiah.carlson | 2008-09-18 21:07:22 -0500 (Thu, 18 Sep 2008) | 2 lines
Fix for documentation bug. Fixes issue 3904.
........
r66512 | raymond.hettinger | 2008-09-19 03:07:48 -0500 (Fri, 19 Sep 2008) | 1 line
Improve docs for super().
........
r66513 | lars.gustaebel | 2008-09-19 07:39:23 -0500 (Fri, 19 Sep 2008) | 2 lines
Correct information about the tarfile module.
........
r66523 | georg.brandl | 2008-09-21 02:14:44 -0500 (Sun, 21 Sep 2008) | 2 lines
#3852: fix some select.kqueue and kevent docs.
........
r66524 | georg.brandl | 2008-09-21 02:15:59 -0500 (Sun, 21 Sep 2008) | 2 lines
#3912: document default for *places* arg.
........
r66525 | georg.brandl | 2008-09-21 02:17:00 -0500 (Sun, 21 Sep 2008) | 2 lines
#3916: fixes for docs wrt. Windows directory layout
........
r66526 | georg.brandl | 2008-09-21 02:18:28 -0500 (Sun, 21 Sep 2008) | 2 lines
#3914: add //= to the augmented assign operators.
........
r66529 | georg.brandl | 2008-09-21 02:24:11 -0500 (Sun, 21 Sep 2008) | 2 lines
#3901: bsddb fix.
........
r66530 | georg.brandl | 2008-09-21 02:31:52 -0500 (Sun, 21 Sep 2008) | 2 lines
#3897: _collections now has an underscore.
........
r66532 | georg.brandl | 2008-09-21 02:36:22 -0500 (Sun, 21 Sep 2008) | 2 lines
Update readme and Makefile (web builder doesn't exist).
........
r66535 | georg.brandl | 2008-09-21 03:03:21 -0500 (Sun, 21 Sep 2008) | 2 lines
#3918: note that uniform() args can be swapped.
........
r66538 | georg.brandl | 2008-09-21 05:03:39 -0500 (Sun, 21 Sep 2008) | 2 lines
Add "dist" target.
........
r66544 | benjamin.peterson | 2008-09-21 16:27:51 -0500 (Sun, 21 Sep 2008) | 4 lines
#3879 fix a regression in urllib.getproxies_environment
reviewers: Benjamin, Georg
........
r66546 | georg.brandl | 2008-09-21 17:31:59 -0500 (Sun, 21 Sep 2008) | 2 lines
Fill out download page.
........
2008-09-22 19:10:59 -03:00
|
|
|
It does so by implementing its own :meth:`__getattribute__` method for searching
|
2009-02-24 19:30:43 -04:00
|
|
|
classes in a predictable order that supports cooperative multiple inheritance.
|
2007-08-15 11:28:22 -03:00
|
|
|
Accordingly, :func:`super` is undefined for implicit lookups using statements or
|
2008-12-06 07:44:00 -04:00
|
|
|
operators such as ``super()[name]``.
|
|
|
|
|
2012-05-19 13:34:13 -03:00
|
|
|
Also note that, aside from the zero argument form, :func:`super` is not
|
|
|
|
limited to use inside methods. The two argument form specifies the
|
|
|
|
arguments exactly and makes the appropriate references. The zero
|
|
|
|
argument form only works inside a class definition, as the compiler fills
|
|
|
|
in the necessary details to correctly retrieve the class being defined,
|
|
|
|
as well as accessing the current instance for ordinary methods.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-06-01 20:17:23 -03:00
|
|
|
For practical suggestions on how to design cooperative classes using
|
|
|
|
:func:`super`, see `guide to using super()
|
2016-02-26 14:37:12 -04:00
|
|
|
<https://rhettinger.wordpress.com/2011/05/26/super-considered-super/>`_.
|
2011-06-01 20:17:23 -03:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
.. _func-tuple:
|
2022-10-15 07:19:35 -03:00
|
|
|
.. class:: tuple()
|
2022-11-19 06:25:45 -04:00
|
|
|
tuple(iterable)
|
2012-08-21 04:42:52 -03:00
|
|
|
:noindex:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-08-21 04:42:52 -03:00
|
|
|
Rather than being a function, :class:`tuple` is actually an immutable
|
2012-10-13 00:28:26 -03:00
|
|
|
sequence type, as documented in :ref:`typesseq-tuple` and :ref:`typesseq`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2022-11-19 06:25:45 -04:00
|
|
|
.. class:: type(object)
|
|
|
|
type(name, bases, dict, **kwds)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2023-05-04 07:04:41 -03:00
|
|
|
.. index:: pair: object; type
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-10-24 17:06:25 -03:00
|
|
|
With one argument, return the type of an *object*. The return value is a
|
2013-10-09 08:02:31 -03:00
|
|
|
type object and generally the same object as returned by
|
|
|
|
:attr:`object.__class__ <instance.__class__>`.
|
2007-08-31 13:33:38 -03:00
|
|
|
|
|
|
|
The :func:`isinstance` built-in function is recommended for testing the type
|
|
|
|
of an object, because it takes subclasses into account.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2012-10-24 17:06:25 -03:00
|
|
|
With three arguments, return a new type object. This is essentially a
|
2021-01-22 01:47:23 -04:00
|
|
|
dynamic form of the :keyword:`class` statement. The *name* string is
|
|
|
|
the class name and becomes the :attr:`~definition.__name__` attribute.
|
|
|
|
The *bases* tuple contains the base classes and becomes the
|
|
|
|
:attr:`~class.__bases__` attribute; if empty, :class:`object`, the
|
|
|
|
ultimate base of all classes, is added. The *dict* dictionary contains
|
|
|
|
attribute and method definitions for the class body; it may be copied
|
|
|
|
or wrapped before becoming the :attr:`~object.__dict__` attribute.
|
|
|
|
The following two statements create identical :class:`type` objects:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-11-21 23:09:19 -04:00
|
|
|
>>> class X:
|
2007-08-15 11:28:22 -03:00
|
|
|
... a = 1
|
2009-01-03 17:18:54 -04:00
|
|
|
...
|
2021-01-22 01:47:23 -04:00
|
|
|
>>> X = type('X', (), dict(a=1))
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-10-13 00:28:26 -03:00
|
|
|
See also :ref:`bltin-type-objects`.
|
|
|
|
|
2021-03-01 19:21:04 -04:00
|
|
|
Keyword arguments provided to the three argument form are passed to the
|
|
|
|
appropriate metaclass machinery (usually :meth:`~object.__init_subclass__`)
|
|
|
|
in the same way that keywords in a class
|
|
|
|
definition (besides *metaclass*) would.
|
|
|
|
|
|
|
|
See also :ref:`class-customization`.
|
|
|
|
|
2016-08-19 05:04:07 -03:00
|
|
|
.. versionchanged:: 3.6
|
|
|
|
Subclasses of :class:`type` which don't override ``type.__new__`` may no
|
|
|
|
longer use the one-argument form to get the type of an object.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-10-15 07:19:35 -03:00
|
|
|
.. function:: vars()
|
2022-11-19 06:25:45 -04:00
|
|
|
vars(object)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2013-10-09 08:02:31 -03:00
|
|
|
Return the :attr:`~object.__dict__` attribute for a module, class, instance,
|
2016-06-18 00:57:31 -03:00
|
|
|
or any other object with a :attr:`~object.__dict__` attribute.
|
Merged revisions 74779-74786,74793,74795,74811,74860-74861,74863,74876,74886,74896,74901,74903,74908,74912,74930,74933,74943,74946,74952-74955,75015,75019,75032,75068,75076,75095,75098,75102,75129,75139,75230 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74779 | michael.foord | 2009-09-13 11:13:36 -0500 (Sun, 13 Sep 2009) | 1 line
Change to tutorial wording for reading text / binary files on Windows. Issue #6301.
........
r74780 | michael.foord | 2009-09-13 11:40:02 -0500 (Sun, 13 Sep 2009) | 1 line
Objects that compare equal automatically pass or fail assertAlmostEqual and assertNotAlmostEqual tests on unittest.TestCase. Issue 6567.
........
r74781 | michael.foord | 2009-09-13 11:46:19 -0500 (Sun, 13 Sep 2009) | 1 line
Note that sys._getframe is not guaranteed to exist in all implementations of Python, and a corresponding note in inspect.currentframe. Issue 6712.
........
r74782 | michael.foord | 2009-09-13 12:07:46 -0500 (Sun, 13 Sep 2009) | 1 line
Tutorial tweaks. Issue 6849.
........
r74783 | michael.foord | 2009-09-13 12:28:35 -0500 (Sun, 13 Sep 2009) | 1 line
unittest.TestLoader.loadTestsFromName honors the loader suiteClass attribute. Issue 6866.
........
r74784 | georg.brandl | 2009-09-13 13:15:07 -0500 (Sun, 13 Sep 2009) | 1 line
Typo fix.
........
r74785 | michael.foord | 2009-09-13 14:07:03 -0500 (Sun, 13 Sep 2009) | 1 line
Test discovery in unittest will only attempt to import modules that are importable; i.e. their names are valid Python identifiers. If an import fails during discovery this will be recorded as an error and test discovery will continue. Issue 6568.
........
r74786 | michael.foord | 2009-09-13 14:08:18 -0500 (Sun, 13 Sep 2009) | 1 line
Remove an extraneous space in unittest documentation.
........
r74793 | georg.brandl | 2009-09-14 09:50:47 -0500 (Mon, 14 Sep 2009) | 1 line
#6908: fix association of hashlib hash attributes.
........
r74795 | benjamin.peterson | 2009-09-14 22:36:26 -0500 (Mon, 14 Sep 2009) | 1 line
Py_SetPythonHome uses static storage #6913
........
r74811 | georg.brandl | 2009-09-15 15:26:59 -0500 (Tue, 15 Sep 2009) | 1 line
Add Armin Ronacher.
........
r74860 | benjamin.peterson | 2009-09-16 21:46:54 -0500 (Wed, 16 Sep 2009) | 1 line
kill bare except
........
r74861 | benjamin.peterson | 2009-09-16 22:18:28 -0500 (Wed, 16 Sep 2009) | 1 line
pep 8 defaults
........
r74863 | benjamin.peterson | 2009-09-16 22:27:33 -0500 (Wed, 16 Sep 2009) | 1 line
rationalize a bit
........
r74876 | georg.brandl | 2009-09-17 11:15:53 -0500 (Thu, 17 Sep 2009) | 1 line
#6932: remove paragraph that advises relying on __del__ being called.
........
r74886 | benjamin.peterson | 2009-09-17 16:33:46 -0500 (Thu, 17 Sep 2009) | 1 line
use macros
........
r74896 | georg.brandl | 2009-09-18 02:22:41 -0500 (Fri, 18 Sep 2009) | 1 line
#6936: for interactive use, quit() is just fine.
........
r74901 | georg.brandl | 2009-09-18 04:14:52 -0500 (Fri, 18 Sep 2009) | 1 line
#6905: use better exception messages in inspect when the argument is of the wrong type.
........
r74903 | georg.brandl | 2009-09-18 04:18:27 -0500 (Fri, 18 Sep 2009) | 1 line
#6938: "ident" is always a string, so use a format code which works.
........
r74908 | georg.brandl | 2009-09-18 08:57:11 -0500 (Fri, 18 Sep 2009) | 1 line
Use str.format() to fix beginner's mistake with %-style string formatting.
........
r74912 | georg.brandl | 2009-09-18 11:19:56 -0500 (Fri, 18 Sep 2009) | 1 line
Optimize optimization and fix method name in docstring.
........
r74930 | georg.brandl | 2009-09-18 16:21:41 -0500 (Fri, 18 Sep 2009) | 1 line
#6925: rewrite docs for locals() and vars() a bit.
........
r74933 | georg.brandl | 2009-09-18 16:35:59 -0500 (Fri, 18 Sep 2009) | 1 line
#6930: clarify description about byteorder handling in UTF decoder routines.
........
r74943 | georg.brandl | 2009-09-19 02:35:07 -0500 (Sat, 19 Sep 2009) | 1 line
#6944: the argument to PyArg_ParseTuple should be a tuple, otherwise a SystemError is set. Also clean up another usage of PyArg_ParseTuple.
........
r74946 | georg.brandl | 2009-09-19 03:43:16 -0500 (Sat, 19 Sep 2009) | 1 line
Update bug tracker reference.
........
r74952 | georg.brandl | 2009-09-19 05:42:34 -0500 (Sat, 19 Sep 2009) | 1 line
#6946: fix duplicate index entries for datetime classes.
........
r74953 | georg.brandl | 2009-09-19 07:04:16 -0500 (Sat, 19 Sep 2009) | 1 line
Fix references to threading.enumerate().
........
r74954 | georg.brandl | 2009-09-19 08:13:56 -0500 (Sat, 19 Sep 2009) | 1 line
Add Doug.
........
r74955 | georg.brandl | 2009-09-19 08:20:49 -0500 (Sat, 19 Sep 2009) | 1 line
Add Mark Summerfield.
........
r75015 | georg.brandl | 2009-09-22 05:55:08 -0500 (Tue, 22 Sep 2009) | 1 line
Fix encoding name.
........
r75019 | vinay.sajip | 2009-09-22 12:23:41 -0500 (Tue, 22 Sep 2009) | 1 line
Fixed a typo, and added sections on optimization and using arbitrary objects as messages.
........
r75032 | benjamin.peterson | 2009-09-22 17:15:28 -0500 (Tue, 22 Sep 2009) | 1 line
fix typos/rephrase
........
r75068 | benjamin.peterson | 2009-09-25 21:57:59 -0500 (Fri, 25 Sep 2009) | 1 line
comment out ugly xxx
........
r75076 | vinay.sajip | 2009-09-26 09:53:32 -0500 (Sat, 26 Sep 2009) | 1 line
Tidied up name of parameter in StreamHandler
........
r75095 | michael.foord | 2009-09-27 14:15:41 -0500 (Sun, 27 Sep 2009) | 1 line
Test creation moved from TestProgram.parseArgs to TestProgram.createTests exclusively. Issue 6956.
........
r75098 | michael.foord | 2009-09-27 15:08:23 -0500 (Sun, 27 Sep 2009) | 1 line
Documentation improvement for load_tests protocol in unittest. Issue 6515.
........
r75102 | skip.montanaro | 2009-09-27 21:12:27 -0500 (Sun, 27 Sep 2009) | 3 lines
Patch from Thomas Barr so that csv.Sniffer will set doublequote property.
Closes issue 6606.
........
r75129 | vinay.sajip | 2009-09-29 02:08:54 -0500 (Tue, 29 Sep 2009) | 1 line
Issue #7014: logging: Improved IronPython 2.6 compatibility.
........
r75139 | raymond.hettinger | 2009-09-29 13:53:24 -0500 (Tue, 29 Sep 2009) | 3 lines
Issue 7008: Better document str.title and show how to work around the apostrophe problem.
........
r75230 | benjamin.peterson | 2009-10-04 08:38:38 -0500 (Sun, 04 Oct 2009) | 1 line
test logging
........
2009-10-04 11:49:41 -03:00
|
|
|
|
2016-06-18 00:57:31 -03:00
|
|
|
Objects such as modules and instances have an updateable :attr:`~object.__dict__`
|
2013-06-02 14:03:05 -03:00
|
|
|
attribute; however, other objects may have write restrictions on their
|
2016-06-18 00:57:31 -03:00
|
|
|
:attr:`~object.__dict__` attributes (for example, classes use a
|
2016-06-24 03:12:01 -03:00
|
|
|
:class:`types.MappingProxyType` to prevent direct dictionary updates).
|
2013-06-02 14:03:05 -03:00
|
|
|
|
|
|
|
Without an argument, :func:`vars` acts like :func:`locals`. Note, the
|
|
|
|
locals dictionary is only useful for reads since updates to the locals
|
|
|
|
dictionary are ignored.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2020-08-21 19:29:34 -03:00
|
|
|
A :exc:`TypeError` exception is raised if an object is specified but
|
|
|
|
it doesn't have a :attr:`~object.__dict__` attribute (for example, if
|
|
|
|
its class defines the :attr:`~object.__slots__` attribute).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2020-06-19 17:39:22 -03:00
|
|
|
.. function:: zip(*iterables, strict=False)
|
|
|
|
|
|
|
|
Iterate over several iterables in parallel, producing tuples with an item
|
|
|
|
from each one.
|
|
|
|
|
|
|
|
Example::
|
|
|
|
|
|
|
|
>>> for item in zip([1, 2, 3], ['sugar', 'spice', 'everything nice']):
|
|
|
|
... print(item)
|
|
|
|
...
|
|
|
|
(1, 'sugar')
|
|
|
|
(2, 'spice')
|
|
|
|
(3, 'everything nice')
|
|
|
|
|
|
|
|
More formally: :func:`zip` returns an iterator of tuples, where the *i*-th
|
|
|
|
tuple contains the *i*-th element from each of the argument iterables.
|
|
|
|
|
|
|
|
Another way to think of :func:`zip` is that it turns rows into columns, and
|
|
|
|
columns into rows. This is similar to `transposing a matrix
|
|
|
|
<https://en.wikipedia.org/wiki/Transpose>`_.
|
|
|
|
|
|
|
|
:func:`zip` is lazy: The elements won't be processed until the iterable is
|
|
|
|
iterated on, e.g. by a :keyword:`!for` loop or by wrapping in a
|
|
|
|
:class:`list`.
|
|
|
|
|
|
|
|
One thing to consider is that the iterables passed to :func:`zip` could have
|
|
|
|
different lengths; sometimes by design, and sometimes because of a bug in
|
|
|
|
the code that prepared these iterables. Python offers three different
|
|
|
|
approaches to dealing with this issue:
|
|
|
|
|
|
|
|
* By default, :func:`zip` stops when the shortest iterable is exhausted.
|
|
|
|
It will ignore the remaining items in the longer iterables, cutting off
|
|
|
|
the result to the length of the shortest iterable::
|
|
|
|
|
|
|
|
>>> list(zip(range(3), ['fee', 'fi', 'fo', 'fum']))
|
|
|
|
[(0, 'fee'), (1, 'fi'), (2, 'fo')]
|
|
|
|
|
|
|
|
* :func:`zip` is often used in cases where the iterables are assumed to be
|
|
|
|
of equal length. In such cases, it's recommended to use the ``strict=True``
|
|
|
|
option. Its output is the same as regular :func:`zip`::
|
|
|
|
|
|
|
|
>>> list(zip(('a', 'b', 'c'), (1, 2, 3), strict=True))
|
|
|
|
[('a', 1), ('b', 2), ('c', 3)]
|
|
|
|
|
2022-12-28 17:24:50 -04:00
|
|
|
Unlike the default behavior, it raises a :exc:`ValueError` if one iterable
|
|
|
|
is exhausted before the others:
|
|
|
|
|
|
|
|
>>> for item in zip(range(3), ['fee', 'fi', 'fo', 'fum'], strict=True): # doctest: +SKIP
|
|
|
|
... print(item)
|
|
|
|
...
|
|
|
|
(0, 'fee')
|
|
|
|
(1, 'fi')
|
|
|
|
(2, 'fo')
|
2020-06-19 17:39:22 -03:00
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
ValueError: zip() argument 2 is longer than argument 1
|
|
|
|
|
2022-12-28 17:24:50 -04:00
|
|
|
..
|
|
|
|
This doctest is disabled because doctest does not support capturing
|
|
|
|
output and exceptions in the same code unit.
|
|
|
|
https://github.com/python/cpython/issues/65382
|
|
|
|
|
2020-06-19 17:39:22 -03:00
|
|
|
Without the ``strict=True`` argument, any bug that results in iterables of
|
2020-06-25 18:50:37 -03:00
|
|
|
different lengths will be silenced, possibly manifesting as a hard-to-find
|
2020-06-19 17:39:22 -03:00
|
|
|
bug in another part of the program.
|
|
|
|
|
|
|
|
* Shorter iterables can be padded with a constant value to make all the
|
|
|
|
iterables have the same length. This is done by
|
|
|
|
:func:`itertools.zip_longest`.
|
|
|
|
|
|
|
|
Edge cases: With a single iterable argument, :func:`zip` returns an
|
|
|
|
iterator of 1-tuples. With no arguments, it returns an empty iterator.
|
|
|
|
|
|
|
|
Tips and tricks:
|
|
|
|
|
|
|
|
* The left-to-right evaluation order of the iterables is guaranteed. This
|
|
|
|
makes possible an idiom for clustering a data series into n-length groups
|
|
|
|
using ``zip(*[iter(s)]*n, strict=True)``. This repeats the *same* iterator
|
|
|
|
``n`` times so that each output tuple has the result of ``n`` calls to the
|
|
|
|
iterator. This has the effect of dividing the input into n-length chunks.
|
|
|
|
|
|
|
|
* :func:`zip` in conjunction with the ``*`` operator can be used to unzip a
|
|
|
|
list::
|
|
|
|
|
|
|
|
>>> x = [1, 2, 3]
|
|
|
|
>>> y = [4, 5, 6]
|
|
|
|
>>> list(zip(x, y))
|
|
|
|
[(1, 4), (2, 5), (3, 6)]
|
|
|
|
>>> x2, y2 = zip(*zip(x, y))
|
|
|
|
>>> x == list(x2) and y == list(y2)
|
|
|
|
True
|
|
|
|
|
|
|
|
.. versionchanged:: 3.10
|
|
|
|
Added the ``strict`` argument.
|
2008-10-10 21:49:57 -03:00
|
|
|
|
Merged revisions 64722,64729,64753,64845-64846,64849,64871,64880-64882,64885,64888,64897,64900-64901,64915,64926-64929,64938-64941,64944,64961,64966,64973 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r64722 | georg.brandl | 2008-07-05 12:13:36 +0200 (Sat, 05 Jul 2008) | 4 lines
#2663: support an *ignore* argument to shutil.copytree(). Patch by Tarek Ziade.
This is a new feature, but Barry authorized adding it in the beta period.
........
r64729 | mark.dickinson | 2008-07-05 13:33:52 +0200 (Sat, 05 Jul 2008) | 5 lines
Issue 3188: accept float('infinity') as well as float('inf'). This
makes the float constructor behave in the same way as specified
by various other language standards, including C99, IEEE 754r,
and the IBM Decimal standard.
........
r64753 | gregory.p.smith | 2008-07-06 05:35:58 +0200 (Sun, 06 Jul 2008) | 4 lines
- Issue #2862: Make int and float freelist management consistent with other
freelists. Changes their CompactFreeList apis into ClearFreeList apis and
calls them via gc.collect().
........
r64845 | raymond.hettinger | 2008-07-10 16:03:19 +0200 (Thu, 10 Jul 2008) | 1 line
Issue 3301: Bisect functions behaved badly when lo was negative.
........
r64846 | raymond.hettinger | 2008-07-10 16:34:57 +0200 (Thu, 10 Jul 2008) | 1 line
Issue 3285: Fractions from_float() and from_decimal() accept Integral arguments.
........
r64849 | andrew.kuchling | 2008-07-10 16:43:31 +0200 (Thu, 10 Jul 2008) | 1 line
Wording changes
........
r64871 | raymond.hettinger | 2008-07-11 14:00:21 +0200 (Fri, 11 Jul 2008) | 1 line
Add cautionary note on the use of PySequence_Fast_ITEMS.
........
r64880 | amaury.forgeotdarc | 2008-07-11 23:28:25 +0200 (Fri, 11 Jul 2008) | 5 lines
#3317 in zipfile module, restore the previous names of global variables:
some applications relied on them.
Also remove duplicated lines.
........
r64881 | amaury.forgeotdarc | 2008-07-11 23:45:06 +0200 (Fri, 11 Jul 2008) | 3 lines
#3342: In tracebacks, printed source lines were not indented since r62555.
#3343: Py_DisplaySourceLine should be a private function. Rename it to _Py_DisplaySourceLine.
........
r64882 | josiah.carlson | 2008-07-12 00:17:14 +0200 (Sat, 12 Jul 2008) | 2 lines
Fix for the AttributeError in test_asynchat.
........
r64885 | josiah.carlson | 2008-07-12 01:26:59 +0200 (Sat, 12 Jul 2008) | 2 lines
Fixed test for asyncore.
........
r64888 | matthias.klose | 2008-07-12 09:51:48 +0200 (Sat, 12 Jul 2008) | 2 lines
- Fix bashisms in Tools/faqwiz/move-faqwiz.sh
........
r64897 | benjamin.peterson | 2008-07-12 22:16:19 +0200 (Sat, 12 Jul 2008) | 1 line
fix various doc typos #3320
........
r64900 | alexandre.vassalotti | 2008-07-13 00:06:53 +0200 (Sun, 13 Jul 2008) | 2 lines
Fixed typo.
........
r64901 | benjamin.peterson | 2008-07-13 01:41:19 +0200 (Sun, 13 Jul 2008) | 1 line
#1778443 robotparser fixes from Aristotelis Mikropoulos
........
r64915 | nick.coghlan | 2008-07-13 16:52:36 +0200 (Sun, 13 Jul 2008) | 1 line
Fix issue 3221 by emitting a RuntimeWarning instead of raising SystemError when the parent module can't be found during an absolute import (likely due to non-PEP 361 aware code which sets a module level __package__ attribute)
........
r64926 | martin.v.loewis | 2008-07-13 22:31:49 +0200 (Sun, 13 Jul 2008) | 2 lines
Add turtle into the module index.
........
r64927 | alexandre.vassalotti | 2008-07-13 22:42:44 +0200 (Sun, 13 Jul 2008) | 3 lines
Issue #3274: Use a less common identifier for the temporary variable
in Py_CLEAR().
........
r64928 | andrew.kuchling | 2008-07-13 23:43:25 +0200 (Sun, 13 Jul 2008) | 1 line
Re-word
........
r64929 | andrew.kuchling | 2008-07-13 23:43:52 +0200 (Sun, 13 Jul 2008) | 1 line
Add various items; move ctypes items into a subsection of their own
........
r64938 | andrew.kuchling | 2008-07-14 02:35:32 +0200 (Mon, 14 Jul 2008) | 1 line
Typo fixes
........
r64939 | andrew.kuchling | 2008-07-14 02:40:55 +0200 (Mon, 14 Jul 2008) | 1 line
Typo fix
........
r64940 | andrew.kuchling | 2008-07-14 03:18:16 +0200 (Mon, 14 Jul 2008) | 1 line
Typo fix
........
r64941 | andrew.kuchling | 2008-07-14 03:18:31 +0200 (Mon, 14 Jul 2008) | 1 line
Expand the multiprocessing section
........
r64944 | gregory.p.smith | 2008-07-14 08:06:48 +0200 (Mon, 14 Jul 2008) | 7 lines
Fix posix.fork1() / os.fork1() to only call PyOS_AfterFork() in the child
process rather than both parent and child.
Does anyone actually use fork1()? It appears to be a Solaris thing
but if Python is built with pthreads on Solaris, fork1() and fork()
should be the same.
........
r64961 | jesse.noller | 2008-07-15 15:47:33 +0200 (Tue, 15 Jul 2008) | 1 line
multiprocessing/connection.py patch to remove fqdn oddness for issue 3270
........
r64966 | nick.coghlan | 2008-07-15 17:40:22 +0200 (Tue, 15 Jul 2008) | 1 line
Add missing NEWS entry for r64962
........
r64973 | jesse.noller | 2008-07-15 20:29:18 +0200 (Tue, 15 Jul 2008) | 1 line
Revert 3270 patch: self._address is in pretty widespread use, need to revisit
........
2008-07-16 09:55:28 -03:00
|
|
|
|
2012-08-06 17:34:44 -03:00
|
|
|
.. function:: __import__(name, globals=None, locals=None, fromlist=(), level=0)
|
2008-12-05 11:55:41 -04:00
|
|
|
|
|
|
|
.. index::
|
2023-05-04 07:48:45 -03:00
|
|
|
pair: statement; import
|
2023-05-04 05:17:12 -03:00
|
|
|
pair: module; builtins
|
2008-12-05 11:55:41 -04:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
This is an advanced function that is not needed in everyday Python
|
2011-07-29 12:50:58 -03:00
|
|
|
programming, unlike :func:`importlib.import_module`.
|
2008-12-05 11:55:41 -04:00
|
|
|
|
Merged revisions 67654,67676-67677,67681,67692,67725,67761,67784-67785,67787-67788,67802,67848-67850,67862-67864,67880,67882 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67654 | georg.brandl | 2008-12-07 16:42:09 -0600 (Sun, 07 Dec 2008) | 2 lines
#4457: rewrite __import__() documentation.
........
r67676 | benjamin.peterson | 2008-12-08 20:03:03 -0600 (Mon, 08 Dec 2008) | 1 line
specify how things are copied
........
r67677 | benjamin.peterson | 2008-12-08 20:05:11 -0600 (Mon, 08 Dec 2008) | 1 line
revert unrelated change to installer script
........
r67681 | jeremy.hylton | 2008-12-09 15:03:10 -0600 (Tue, 09 Dec 2008) | 2 lines
Add simple unittests for Request
........
r67692 | amaury.forgeotdarc | 2008-12-10 18:03:42 -0600 (Wed, 10 Dec 2008) | 2 lines
#1030250: correctly pass the dry_run option to the mkpath() function.
........
r67725 | benjamin.peterson | 2008-12-12 22:02:20 -0600 (Fri, 12 Dec 2008) | 1 line
fix incorrect example
........
r67761 | benjamin.peterson | 2008-12-14 11:26:04 -0600 (Sun, 14 Dec 2008) | 1 line
fix missing bracket
........
r67784 | georg.brandl | 2008-12-15 02:33:58 -0600 (Mon, 15 Dec 2008) | 2 lines
#4446: document "platforms" argument for setup().
........
r67785 | georg.brandl | 2008-12-15 02:36:11 -0600 (Mon, 15 Dec 2008) | 2 lines
#4611: fix typo.
........
r67787 | georg.brandl | 2008-12-15 02:58:59 -0600 (Mon, 15 Dec 2008) | 2 lines
#4578: fix has_key() usage in compiler package.
........
r67788 | georg.brandl | 2008-12-15 03:07:39 -0600 (Mon, 15 Dec 2008) | 2 lines
#4568: remove limitation in varargs callback example.
........
r67802 | amaury.forgeotdarc | 2008-12-15 16:29:14 -0600 (Mon, 15 Dec 2008) | 4 lines
#3632: the "pyo" macro from gdbinit can now run when the GIL is released.
Patch by haypo.
........
r67848 | benjamin.peterson | 2008-12-18 20:28:56 -0600 (Thu, 18 Dec 2008) | 1 line
fix typo
........
r67849 | benjamin.peterson | 2008-12-18 20:31:35 -0600 (Thu, 18 Dec 2008) | 1 line
_call_method -> _callmethod and _get_value to _getvalue
........
r67850 | raymond.hettinger | 2008-12-19 03:06:07 -0600 (Fri, 19 Dec 2008) | 9 lines
Fix-up and clean-up docs for int.bit_length().
* Replace dramatic footnote with in-line comment about possible round-off errors in logarithms of large numbers.
* Add comments to the pure python code equivalent.
* replace floor() with int() in the mathematical equivalent so the type is correct (should be an int, not a float).
* add abs() to the mathematical equivalent so that it matches the previous line that it is supposed to be equivalent to.
* make one combined example with a negative input.
........
r67862 | benjamin.peterson | 2008-12-19 20:48:02 -0600 (Fri, 19 Dec 2008) | 1 line
copy sentence from docstring
........
r67863 | benjamin.peterson | 2008-12-19 20:51:26 -0600 (Fri, 19 Dec 2008) | 1 line
add headings
........
r67864 | benjamin.peterson | 2008-12-19 20:57:19 -0600 (Fri, 19 Dec 2008) | 1 line
beef up docstring
........
r67880 | benjamin.peterson | 2008-12-20 16:49:24 -0600 (Sat, 20 Dec 2008) | 1 line
remove redundant sentence
........
r67882 | benjamin.peterson | 2008-12-20 16:59:49 -0600 (Sat, 20 Dec 2008) | 1 line
add some recent releases to the list
........
2008-12-20 20:06:59 -04:00
|
|
|
This function is invoked by the :keyword:`import` statement. It can be
|
|
|
|
replaced (by importing the :mod:`builtins` module and assigning to
|
|
|
|
``builtins.__import__``) in order to change semantics of the
|
2018-12-19 02:09:46 -04:00
|
|
|
:keyword:`!import` statement, but doing so is **strongly** discouraged as it
|
2013-08-23 11:58:49 -03:00
|
|
|
is usually simpler to use import hooks (see :pep:`302`) to attain the same
|
|
|
|
goals and does not cause issues with code which assumes the default import
|
|
|
|
implementation is in use. Direct use of :func:`__import__` is also
|
|
|
|
discouraged in favor of :func:`importlib.import_module`.
|
Merged revisions 67654,67676-67677,67681,67692,67725,67761,67784-67785,67787-67788,67802,67848-67850,67862-67864,67880,67882 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67654 | georg.brandl | 2008-12-07 16:42:09 -0600 (Sun, 07 Dec 2008) | 2 lines
#4457: rewrite __import__() documentation.
........
r67676 | benjamin.peterson | 2008-12-08 20:03:03 -0600 (Mon, 08 Dec 2008) | 1 line
specify how things are copied
........
r67677 | benjamin.peterson | 2008-12-08 20:05:11 -0600 (Mon, 08 Dec 2008) | 1 line
revert unrelated change to installer script
........
r67681 | jeremy.hylton | 2008-12-09 15:03:10 -0600 (Tue, 09 Dec 2008) | 2 lines
Add simple unittests for Request
........
r67692 | amaury.forgeotdarc | 2008-12-10 18:03:42 -0600 (Wed, 10 Dec 2008) | 2 lines
#1030250: correctly pass the dry_run option to the mkpath() function.
........
r67725 | benjamin.peterson | 2008-12-12 22:02:20 -0600 (Fri, 12 Dec 2008) | 1 line
fix incorrect example
........
r67761 | benjamin.peterson | 2008-12-14 11:26:04 -0600 (Sun, 14 Dec 2008) | 1 line
fix missing bracket
........
r67784 | georg.brandl | 2008-12-15 02:33:58 -0600 (Mon, 15 Dec 2008) | 2 lines
#4446: document "platforms" argument for setup().
........
r67785 | georg.brandl | 2008-12-15 02:36:11 -0600 (Mon, 15 Dec 2008) | 2 lines
#4611: fix typo.
........
r67787 | georg.brandl | 2008-12-15 02:58:59 -0600 (Mon, 15 Dec 2008) | 2 lines
#4578: fix has_key() usage in compiler package.
........
r67788 | georg.brandl | 2008-12-15 03:07:39 -0600 (Mon, 15 Dec 2008) | 2 lines
#4568: remove limitation in varargs callback example.
........
r67802 | amaury.forgeotdarc | 2008-12-15 16:29:14 -0600 (Mon, 15 Dec 2008) | 4 lines
#3632: the "pyo" macro from gdbinit can now run when the GIL is released.
Patch by haypo.
........
r67848 | benjamin.peterson | 2008-12-18 20:28:56 -0600 (Thu, 18 Dec 2008) | 1 line
fix typo
........
r67849 | benjamin.peterson | 2008-12-18 20:31:35 -0600 (Thu, 18 Dec 2008) | 1 line
_call_method -> _callmethod and _get_value to _getvalue
........
r67850 | raymond.hettinger | 2008-12-19 03:06:07 -0600 (Fri, 19 Dec 2008) | 9 lines
Fix-up and clean-up docs for int.bit_length().
* Replace dramatic footnote with in-line comment about possible round-off errors in logarithms of large numbers.
* Add comments to the pure python code equivalent.
* replace floor() with int() in the mathematical equivalent so the type is correct (should be an int, not a float).
* add abs() to the mathematical equivalent so that it matches the previous line that it is supposed to be equivalent to.
* make one combined example with a negative input.
........
r67862 | benjamin.peterson | 2008-12-19 20:48:02 -0600 (Fri, 19 Dec 2008) | 1 line
copy sentence from docstring
........
r67863 | benjamin.peterson | 2008-12-19 20:51:26 -0600 (Fri, 19 Dec 2008) | 1 line
add headings
........
r67864 | benjamin.peterson | 2008-12-19 20:57:19 -0600 (Fri, 19 Dec 2008) | 1 line
beef up docstring
........
r67880 | benjamin.peterson | 2008-12-20 16:49:24 -0600 (Sat, 20 Dec 2008) | 1 line
remove redundant sentence
........
r67882 | benjamin.peterson | 2008-12-20 16:59:49 -0600 (Sat, 20 Dec 2008) | 1 line
add some recent releases to the list
........
2008-12-20 20:06:59 -04:00
|
|
|
|
|
|
|
The function imports the module *name*, potentially using the given *globals*
|
|
|
|
and *locals* to determine how to interpret the name in a package context.
|
|
|
|
The *fromlist* gives the names of objects or submodules that should be
|
|
|
|
imported from the module given by *name*. The standard implementation does
|
2021-07-19 13:02:23 -03:00
|
|
|
not use its *locals* argument at all and uses its *globals* only to
|
Merged revisions 67654,67676-67677,67681,67692,67725,67761,67784-67785,67787-67788,67802,67848-67850,67862-67864,67880,67882 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67654 | georg.brandl | 2008-12-07 16:42:09 -0600 (Sun, 07 Dec 2008) | 2 lines
#4457: rewrite __import__() documentation.
........
r67676 | benjamin.peterson | 2008-12-08 20:03:03 -0600 (Mon, 08 Dec 2008) | 1 line
specify how things are copied
........
r67677 | benjamin.peterson | 2008-12-08 20:05:11 -0600 (Mon, 08 Dec 2008) | 1 line
revert unrelated change to installer script
........
r67681 | jeremy.hylton | 2008-12-09 15:03:10 -0600 (Tue, 09 Dec 2008) | 2 lines
Add simple unittests for Request
........
r67692 | amaury.forgeotdarc | 2008-12-10 18:03:42 -0600 (Wed, 10 Dec 2008) | 2 lines
#1030250: correctly pass the dry_run option to the mkpath() function.
........
r67725 | benjamin.peterson | 2008-12-12 22:02:20 -0600 (Fri, 12 Dec 2008) | 1 line
fix incorrect example
........
r67761 | benjamin.peterson | 2008-12-14 11:26:04 -0600 (Sun, 14 Dec 2008) | 1 line
fix missing bracket
........
r67784 | georg.brandl | 2008-12-15 02:33:58 -0600 (Mon, 15 Dec 2008) | 2 lines
#4446: document "platforms" argument for setup().
........
r67785 | georg.brandl | 2008-12-15 02:36:11 -0600 (Mon, 15 Dec 2008) | 2 lines
#4611: fix typo.
........
r67787 | georg.brandl | 2008-12-15 02:58:59 -0600 (Mon, 15 Dec 2008) | 2 lines
#4578: fix has_key() usage in compiler package.
........
r67788 | georg.brandl | 2008-12-15 03:07:39 -0600 (Mon, 15 Dec 2008) | 2 lines
#4568: remove limitation in varargs callback example.
........
r67802 | amaury.forgeotdarc | 2008-12-15 16:29:14 -0600 (Mon, 15 Dec 2008) | 4 lines
#3632: the "pyo" macro from gdbinit can now run when the GIL is released.
Patch by haypo.
........
r67848 | benjamin.peterson | 2008-12-18 20:28:56 -0600 (Thu, 18 Dec 2008) | 1 line
fix typo
........
r67849 | benjamin.peterson | 2008-12-18 20:31:35 -0600 (Thu, 18 Dec 2008) | 1 line
_call_method -> _callmethod and _get_value to _getvalue
........
r67850 | raymond.hettinger | 2008-12-19 03:06:07 -0600 (Fri, 19 Dec 2008) | 9 lines
Fix-up and clean-up docs for int.bit_length().
* Replace dramatic footnote with in-line comment about possible round-off errors in logarithms of large numbers.
* Add comments to the pure python code equivalent.
* replace floor() with int() in the mathematical equivalent so the type is correct (should be an int, not a float).
* add abs() to the mathematical equivalent so that it matches the previous line that it is supposed to be equivalent to.
* make one combined example with a negative input.
........
r67862 | benjamin.peterson | 2008-12-19 20:48:02 -0600 (Fri, 19 Dec 2008) | 1 line
copy sentence from docstring
........
r67863 | benjamin.peterson | 2008-12-19 20:51:26 -0600 (Fri, 19 Dec 2008) | 1 line
add headings
........
r67864 | benjamin.peterson | 2008-12-19 20:57:19 -0600 (Fri, 19 Dec 2008) | 1 line
beef up docstring
........
r67880 | benjamin.peterson | 2008-12-20 16:49:24 -0600 (Sat, 20 Dec 2008) | 1 line
remove redundant sentence
........
r67882 | benjamin.peterson | 2008-12-20 16:59:49 -0600 (Sat, 20 Dec 2008) | 1 line
add some recent releases to the list
........
2008-12-20 20:06:59 -04:00
|
|
|
determine the package context of the :keyword:`import` statement.
|
|
|
|
|
2009-03-14 23:18:41 -03:00
|
|
|
*level* specifies whether to use absolute or relative imports. ``0`` (the
|
|
|
|
default) means only perform absolute imports. Positive values for
|
Merged revisions 67654,67676-67677,67681,67692,67725,67761,67784-67785,67787-67788,67802,67848-67850,67862-67864,67880,67882 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67654 | georg.brandl | 2008-12-07 16:42:09 -0600 (Sun, 07 Dec 2008) | 2 lines
#4457: rewrite __import__() documentation.
........
r67676 | benjamin.peterson | 2008-12-08 20:03:03 -0600 (Mon, 08 Dec 2008) | 1 line
specify how things are copied
........
r67677 | benjamin.peterson | 2008-12-08 20:05:11 -0600 (Mon, 08 Dec 2008) | 1 line
revert unrelated change to installer script
........
r67681 | jeremy.hylton | 2008-12-09 15:03:10 -0600 (Tue, 09 Dec 2008) | 2 lines
Add simple unittests for Request
........
r67692 | amaury.forgeotdarc | 2008-12-10 18:03:42 -0600 (Wed, 10 Dec 2008) | 2 lines
#1030250: correctly pass the dry_run option to the mkpath() function.
........
r67725 | benjamin.peterson | 2008-12-12 22:02:20 -0600 (Fri, 12 Dec 2008) | 1 line
fix incorrect example
........
r67761 | benjamin.peterson | 2008-12-14 11:26:04 -0600 (Sun, 14 Dec 2008) | 1 line
fix missing bracket
........
r67784 | georg.brandl | 2008-12-15 02:33:58 -0600 (Mon, 15 Dec 2008) | 2 lines
#4446: document "platforms" argument for setup().
........
r67785 | georg.brandl | 2008-12-15 02:36:11 -0600 (Mon, 15 Dec 2008) | 2 lines
#4611: fix typo.
........
r67787 | georg.brandl | 2008-12-15 02:58:59 -0600 (Mon, 15 Dec 2008) | 2 lines
#4578: fix has_key() usage in compiler package.
........
r67788 | georg.brandl | 2008-12-15 03:07:39 -0600 (Mon, 15 Dec 2008) | 2 lines
#4568: remove limitation in varargs callback example.
........
r67802 | amaury.forgeotdarc | 2008-12-15 16:29:14 -0600 (Mon, 15 Dec 2008) | 4 lines
#3632: the "pyo" macro from gdbinit can now run when the GIL is released.
Patch by haypo.
........
r67848 | benjamin.peterson | 2008-12-18 20:28:56 -0600 (Thu, 18 Dec 2008) | 1 line
fix typo
........
r67849 | benjamin.peterson | 2008-12-18 20:31:35 -0600 (Thu, 18 Dec 2008) | 1 line
_call_method -> _callmethod and _get_value to _getvalue
........
r67850 | raymond.hettinger | 2008-12-19 03:06:07 -0600 (Fri, 19 Dec 2008) | 9 lines
Fix-up and clean-up docs for int.bit_length().
* Replace dramatic footnote with in-line comment about possible round-off errors in logarithms of large numbers.
* Add comments to the pure python code equivalent.
* replace floor() with int() in the mathematical equivalent so the type is correct (should be an int, not a float).
* add abs() to the mathematical equivalent so that it matches the previous line that it is supposed to be equivalent to.
* make one combined example with a negative input.
........
r67862 | benjamin.peterson | 2008-12-19 20:48:02 -0600 (Fri, 19 Dec 2008) | 1 line
copy sentence from docstring
........
r67863 | benjamin.peterson | 2008-12-19 20:51:26 -0600 (Fri, 19 Dec 2008) | 1 line
add headings
........
r67864 | benjamin.peterson | 2008-12-19 20:57:19 -0600 (Fri, 19 Dec 2008) | 1 line
beef up docstring
........
r67880 | benjamin.peterson | 2008-12-20 16:49:24 -0600 (Sat, 20 Dec 2008) | 1 line
remove redundant sentence
........
r67882 | benjamin.peterson | 2008-12-20 16:59:49 -0600 (Sat, 20 Dec 2008) | 1 line
add some recent releases to the list
........
2008-12-20 20:06:59 -04:00
|
|
|
*level* indicate the number of parent directories to search relative to the
|
2012-04-14 22:58:33 -03:00
|
|
|
directory of the module calling :func:`__import__` (see :pep:`328` for the
|
|
|
|
details).
|
2008-12-05 11:55:41 -04:00
|
|
|
|
|
|
|
When the *name* variable is of the form ``package.module``, normally, the
|
|
|
|
top-level package (the name up till the first dot) is returned, *not* the
|
|
|
|
module named by *name*. However, when a non-empty *fromlist* argument is
|
Merged revisions 67654,67676-67677,67681,67692,67725,67761,67784-67785,67787-67788,67802,67848-67850,67862-67864,67880,67882 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67654 | georg.brandl | 2008-12-07 16:42:09 -0600 (Sun, 07 Dec 2008) | 2 lines
#4457: rewrite __import__() documentation.
........
r67676 | benjamin.peterson | 2008-12-08 20:03:03 -0600 (Mon, 08 Dec 2008) | 1 line
specify how things are copied
........
r67677 | benjamin.peterson | 2008-12-08 20:05:11 -0600 (Mon, 08 Dec 2008) | 1 line
revert unrelated change to installer script
........
r67681 | jeremy.hylton | 2008-12-09 15:03:10 -0600 (Tue, 09 Dec 2008) | 2 lines
Add simple unittests for Request
........
r67692 | amaury.forgeotdarc | 2008-12-10 18:03:42 -0600 (Wed, 10 Dec 2008) | 2 lines
#1030250: correctly pass the dry_run option to the mkpath() function.
........
r67725 | benjamin.peterson | 2008-12-12 22:02:20 -0600 (Fri, 12 Dec 2008) | 1 line
fix incorrect example
........
r67761 | benjamin.peterson | 2008-12-14 11:26:04 -0600 (Sun, 14 Dec 2008) | 1 line
fix missing bracket
........
r67784 | georg.brandl | 2008-12-15 02:33:58 -0600 (Mon, 15 Dec 2008) | 2 lines
#4446: document "platforms" argument for setup().
........
r67785 | georg.brandl | 2008-12-15 02:36:11 -0600 (Mon, 15 Dec 2008) | 2 lines
#4611: fix typo.
........
r67787 | georg.brandl | 2008-12-15 02:58:59 -0600 (Mon, 15 Dec 2008) | 2 lines
#4578: fix has_key() usage in compiler package.
........
r67788 | georg.brandl | 2008-12-15 03:07:39 -0600 (Mon, 15 Dec 2008) | 2 lines
#4568: remove limitation in varargs callback example.
........
r67802 | amaury.forgeotdarc | 2008-12-15 16:29:14 -0600 (Mon, 15 Dec 2008) | 4 lines
#3632: the "pyo" macro from gdbinit can now run when the GIL is released.
Patch by haypo.
........
r67848 | benjamin.peterson | 2008-12-18 20:28:56 -0600 (Thu, 18 Dec 2008) | 1 line
fix typo
........
r67849 | benjamin.peterson | 2008-12-18 20:31:35 -0600 (Thu, 18 Dec 2008) | 1 line
_call_method -> _callmethod and _get_value to _getvalue
........
r67850 | raymond.hettinger | 2008-12-19 03:06:07 -0600 (Fri, 19 Dec 2008) | 9 lines
Fix-up and clean-up docs for int.bit_length().
* Replace dramatic footnote with in-line comment about possible round-off errors in logarithms of large numbers.
* Add comments to the pure python code equivalent.
* replace floor() with int() in the mathematical equivalent so the type is correct (should be an int, not a float).
* add abs() to the mathematical equivalent so that it matches the previous line that it is supposed to be equivalent to.
* make one combined example with a negative input.
........
r67862 | benjamin.peterson | 2008-12-19 20:48:02 -0600 (Fri, 19 Dec 2008) | 1 line
copy sentence from docstring
........
r67863 | benjamin.peterson | 2008-12-19 20:51:26 -0600 (Fri, 19 Dec 2008) | 1 line
add headings
........
r67864 | benjamin.peterson | 2008-12-19 20:57:19 -0600 (Fri, 19 Dec 2008) | 1 line
beef up docstring
........
r67880 | benjamin.peterson | 2008-12-20 16:49:24 -0600 (Sat, 20 Dec 2008) | 1 line
remove redundant sentence
........
r67882 | benjamin.peterson | 2008-12-20 16:59:49 -0600 (Sat, 20 Dec 2008) | 1 line
add some recent releases to the list
........
2008-12-20 20:06:59 -04:00
|
|
|
given, the module named by *name* is returned.
|
2008-12-05 11:55:41 -04:00
|
|
|
|
Merged revisions 67654,67676-67677,67681,67692,67725,67761,67784-67785,67787-67788,67802,67848-67850,67862-67864,67880,67882 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67654 | georg.brandl | 2008-12-07 16:42:09 -0600 (Sun, 07 Dec 2008) | 2 lines
#4457: rewrite __import__() documentation.
........
r67676 | benjamin.peterson | 2008-12-08 20:03:03 -0600 (Mon, 08 Dec 2008) | 1 line
specify how things are copied
........
r67677 | benjamin.peterson | 2008-12-08 20:05:11 -0600 (Mon, 08 Dec 2008) | 1 line
revert unrelated change to installer script
........
r67681 | jeremy.hylton | 2008-12-09 15:03:10 -0600 (Tue, 09 Dec 2008) | 2 lines
Add simple unittests for Request
........
r67692 | amaury.forgeotdarc | 2008-12-10 18:03:42 -0600 (Wed, 10 Dec 2008) | 2 lines
#1030250: correctly pass the dry_run option to the mkpath() function.
........
r67725 | benjamin.peterson | 2008-12-12 22:02:20 -0600 (Fri, 12 Dec 2008) | 1 line
fix incorrect example
........
r67761 | benjamin.peterson | 2008-12-14 11:26:04 -0600 (Sun, 14 Dec 2008) | 1 line
fix missing bracket
........
r67784 | georg.brandl | 2008-12-15 02:33:58 -0600 (Mon, 15 Dec 2008) | 2 lines
#4446: document "platforms" argument for setup().
........
r67785 | georg.brandl | 2008-12-15 02:36:11 -0600 (Mon, 15 Dec 2008) | 2 lines
#4611: fix typo.
........
r67787 | georg.brandl | 2008-12-15 02:58:59 -0600 (Mon, 15 Dec 2008) | 2 lines
#4578: fix has_key() usage in compiler package.
........
r67788 | georg.brandl | 2008-12-15 03:07:39 -0600 (Mon, 15 Dec 2008) | 2 lines
#4568: remove limitation in varargs callback example.
........
r67802 | amaury.forgeotdarc | 2008-12-15 16:29:14 -0600 (Mon, 15 Dec 2008) | 4 lines
#3632: the "pyo" macro from gdbinit can now run when the GIL is released.
Patch by haypo.
........
r67848 | benjamin.peterson | 2008-12-18 20:28:56 -0600 (Thu, 18 Dec 2008) | 1 line
fix typo
........
r67849 | benjamin.peterson | 2008-12-18 20:31:35 -0600 (Thu, 18 Dec 2008) | 1 line
_call_method -> _callmethod and _get_value to _getvalue
........
r67850 | raymond.hettinger | 2008-12-19 03:06:07 -0600 (Fri, 19 Dec 2008) | 9 lines
Fix-up and clean-up docs for int.bit_length().
* Replace dramatic footnote with in-line comment about possible round-off errors in logarithms of large numbers.
* Add comments to the pure python code equivalent.
* replace floor() with int() in the mathematical equivalent so the type is correct (should be an int, not a float).
* add abs() to the mathematical equivalent so that it matches the previous line that it is supposed to be equivalent to.
* make one combined example with a negative input.
........
r67862 | benjamin.peterson | 2008-12-19 20:48:02 -0600 (Fri, 19 Dec 2008) | 1 line
copy sentence from docstring
........
r67863 | benjamin.peterson | 2008-12-19 20:51:26 -0600 (Fri, 19 Dec 2008) | 1 line
add headings
........
r67864 | benjamin.peterson | 2008-12-19 20:57:19 -0600 (Fri, 19 Dec 2008) | 1 line
beef up docstring
........
r67880 | benjamin.peterson | 2008-12-20 16:49:24 -0600 (Sat, 20 Dec 2008) | 1 line
remove redundant sentence
........
r67882 | benjamin.peterson | 2008-12-20 16:59:49 -0600 (Sat, 20 Dec 2008) | 1 line
add some recent releases to the list
........
2008-12-20 20:06:59 -04:00
|
|
|
For example, the statement ``import spam`` results in bytecode resembling the
|
|
|
|
following code::
|
2009-01-03 17:18:54 -04:00
|
|
|
|
2009-03-14 23:18:41 -03:00
|
|
|
spam = __import__('spam', globals(), locals(), [], 0)
|
Merged revisions 67654,67676-67677,67681,67692,67725,67761,67784-67785,67787-67788,67802,67848-67850,67862-67864,67880,67882 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67654 | georg.brandl | 2008-12-07 16:42:09 -0600 (Sun, 07 Dec 2008) | 2 lines
#4457: rewrite __import__() documentation.
........
r67676 | benjamin.peterson | 2008-12-08 20:03:03 -0600 (Mon, 08 Dec 2008) | 1 line
specify how things are copied
........
r67677 | benjamin.peterson | 2008-12-08 20:05:11 -0600 (Mon, 08 Dec 2008) | 1 line
revert unrelated change to installer script
........
r67681 | jeremy.hylton | 2008-12-09 15:03:10 -0600 (Tue, 09 Dec 2008) | 2 lines
Add simple unittests for Request
........
r67692 | amaury.forgeotdarc | 2008-12-10 18:03:42 -0600 (Wed, 10 Dec 2008) | 2 lines
#1030250: correctly pass the dry_run option to the mkpath() function.
........
r67725 | benjamin.peterson | 2008-12-12 22:02:20 -0600 (Fri, 12 Dec 2008) | 1 line
fix incorrect example
........
r67761 | benjamin.peterson | 2008-12-14 11:26:04 -0600 (Sun, 14 Dec 2008) | 1 line
fix missing bracket
........
r67784 | georg.brandl | 2008-12-15 02:33:58 -0600 (Mon, 15 Dec 2008) | 2 lines
#4446: document "platforms" argument for setup().
........
r67785 | georg.brandl | 2008-12-15 02:36:11 -0600 (Mon, 15 Dec 2008) | 2 lines
#4611: fix typo.
........
r67787 | georg.brandl | 2008-12-15 02:58:59 -0600 (Mon, 15 Dec 2008) | 2 lines
#4578: fix has_key() usage in compiler package.
........
r67788 | georg.brandl | 2008-12-15 03:07:39 -0600 (Mon, 15 Dec 2008) | 2 lines
#4568: remove limitation in varargs callback example.
........
r67802 | amaury.forgeotdarc | 2008-12-15 16:29:14 -0600 (Mon, 15 Dec 2008) | 4 lines
#3632: the "pyo" macro from gdbinit can now run when the GIL is released.
Patch by haypo.
........
r67848 | benjamin.peterson | 2008-12-18 20:28:56 -0600 (Thu, 18 Dec 2008) | 1 line
fix typo
........
r67849 | benjamin.peterson | 2008-12-18 20:31:35 -0600 (Thu, 18 Dec 2008) | 1 line
_call_method -> _callmethod and _get_value to _getvalue
........
r67850 | raymond.hettinger | 2008-12-19 03:06:07 -0600 (Fri, 19 Dec 2008) | 9 lines
Fix-up and clean-up docs for int.bit_length().
* Replace dramatic footnote with in-line comment about possible round-off errors in logarithms of large numbers.
* Add comments to the pure python code equivalent.
* replace floor() with int() in the mathematical equivalent so the type is correct (should be an int, not a float).
* add abs() to the mathematical equivalent so that it matches the previous line that it is supposed to be equivalent to.
* make one combined example with a negative input.
........
r67862 | benjamin.peterson | 2008-12-19 20:48:02 -0600 (Fri, 19 Dec 2008) | 1 line
copy sentence from docstring
........
r67863 | benjamin.peterson | 2008-12-19 20:51:26 -0600 (Fri, 19 Dec 2008) | 1 line
add headings
........
r67864 | benjamin.peterson | 2008-12-19 20:57:19 -0600 (Fri, 19 Dec 2008) | 1 line
beef up docstring
........
r67880 | benjamin.peterson | 2008-12-20 16:49:24 -0600 (Sat, 20 Dec 2008) | 1 line
remove redundant sentence
........
r67882 | benjamin.peterson | 2008-12-20 16:59:49 -0600 (Sat, 20 Dec 2008) | 1 line
add some recent releases to the list
........
2008-12-20 20:06:59 -04:00
|
|
|
|
|
|
|
The statement ``import spam.ham`` results in this call::
|
|
|
|
|
2009-03-14 23:18:41 -03:00
|
|
|
spam = __import__('spam.ham', globals(), locals(), [], 0)
|
Merged revisions 67654,67676-67677,67681,67692,67725,67761,67784-67785,67787-67788,67802,67848-67850,67862-67864,67880,67882 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67654 | georg.brandl | 2008-12-07 16:42:09 -0600 (Sun, 07 Dec 2008) | 2 lines
#4457: rewrite __import__() documentation.
........
r67676 | benjamin.peterson | 2008-12-08 20:03:03 -0600 (Mon, 08 Dec 2008) | 1 line
specify how things are copied
........
r67677 | benjamin.peterson | 2008-12-08 20:05:11 -0600 (Mon, 08 Dec 2008) | 1 line
revert unrelated change to installer script
........
r67681 | jeremy.hylton | 2008-12-09 15:03:10 -0600 (Tue, 09 Dec 2008) | 2 lines
Add simple unittests for Request
........
r67692 | amaury.forgeotdarc | 2008-12-10 18:03:42 -0600 (Wed, 10 Dec 2008) | 2 lines
#1030250: correctly pass the dry_run option to the mkpath() function.
........
r67725 | benjamin.peterson | 2008-12-12 22:02:20 -0600 (Fri, 12 Dec 2008) | 1 line
fix incorrect example
........
r67761 | benjamin.peterson | 2008-12-14 11:26:04 -0600 (Sun, 14 Dec 2008) | 1 line
fix missing bracket
........
r67784 | georg.brandl | 2008-12-15 02:33:58 -0600 (Mon, 15 Dec 2008) | 2 lines
#4446: document "platforms" argument for setup().
........
r67785 | georg.brandl | 2008-12-15 02:36:11 -0600 (Mon, 15 Dec 2008) | 2 lines
#4611: fix typo.
........
r67787 | georg.brandl | 2008-12-15 02:58:59 -0600 (Mon, 15 Dec 2008) | 2 lines
#4578: fix has_key() usage in compiler package.
........
r67788 | georg.brandl | 2008-12-15 03:07:39 -0600 (Mon, 15 Dec 2008) | 2 lines
#4568: remove limitation in varargs callback example.
........
r67802 | amaury.forgeotdarc | 2008-12-15 16:29:14 -0600 (Mon, 15 Dec 2008) | 4 lines
#3632: the "pyo" macro from gdbinit can now run when the GIL is released.
Patch by haypo.
........
r67848 | benjamin.peterson | 2008-12-18 20:28:56 -0600 (Thu, 18 Dec 2008) | 1 line
fix typo
........
r67849 | benjamin.peterson | 2008-12-18 20:31:35 -0600 (Thu, 18 Dec 2008) | 1 line
_call_method -> _callmethod and _get_value to _getvalue
........
r67850 | raymond.hettinger | 2008-12-19 03:06:07 -0600 (Fri, 19 Dec 2008) | 9 lines
Fix-up and clean-up docs for int.bit_length().
* Replace dramatic footnote with in-line comment about possible round-off errors in logarithms of large numbers.
* Add comments to the pure python code equivalent.
* replace floor() with int() in the mathematical equivalent so the type is correct (should be an int, not a float).
* add abs() to the mathematical equivalent so that it matches the previous line that it is supposed to be equivalent to.
* make one combined example with a negative input.
........
r67862 | benjamin.peterson | 2008-12-19 20:48:02 -0600 (Fri, 19 Dec 2008) | 1 line
copy sentence from docstring
........
r67863 | benjamin.peterson | 2008-12-19 20:51:26 -0600 (Fri, 19 Dec 2008) | 1 line
add headings
........
r67864 | benjamin.peterson | 2008-12-19 20:57:19 -0600 (Fri, 19 Dec 2008) | 1 line
beef up docstring
........
r67880 | benjamin.peterson | 2008-12-20 16:49:24 -0600 (Sat, 20 Dec 2008) | 1 line
remove redundant sentence
........
r67882 | benjamin.peterson | 2008-12-20 16:59:49 -0600 (Sat, 20 Dec 2008) | 1 line
add some recent releases to the list
........
2008-12-20 20:06:59 -04:00
|
|
|
|
|
|
|
Note how :func:`__import__` returns the toplevel module here because this is
|
|
|
|
the object that is bound to a name by the :keyword:`import` statement.
|
|
|
|
|
|
|
|
On the other hand, the statement ``from spam.ham import eggs, sausage as
|
|
|
|
saus`` results in ::
|
|
|
|
|
2009-03-14 23:18:41 -03:00
|
|
|
_temp = __import__('spam.ham', globals(), locals(), ['eggs', 'sausage'], 0)
|
Merged revisions 67654,67676-67677,67681,67692,67725,67761,67784-67785,67787-67788,67802,67848-67850,67862-67864,67880,67882 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67654 | georg.brandl | 2008-12-07 16:42:09 -0600 (Sun, 07 Dec 2008) | 2 lines
#4457: rewrite __import__() documentation.
........
r67676 | benjamin.peterson | 2008-12-08 20:03:03 -0600 (Mon, 08 Dec 2008) | 1 line
specify how things are copied
........
r67677 | benjamin.peterson | 2008-12-08 20:05:11 -0600 (Mon, 08 Dec 2008) | 1 line
revert unrelated change to installer script
........
r67681 | jeremy.hylton | 2008-12-09 15:03:10 -0600 (Tue, 09 Dec 2008) | 2 lines
Add simple unittests for Request
........
r67692 | amaury.forgeotdarc | 2008-12-10 18:03:42 -0600 (Wed, 10 Dec 2008) | 2 lines
#1030250: correctly pass the dry_run option to the mkpath() function.
........
r67725 | benjamin.peterson | 2008-12-12 22:02:20 -0600 (Fri, 12 Dec 2008) | 1 line
fix incorrect example
........
r67761 | benjamin.peterson | 2008-12-14 11:26:04 -0600 (Sun, 14 Dec 2008) | 1 line
fix missing bracket
........
r67784 | georg.brandl | 2008-12-15 02:33:58 -0600 (Mon, 15 Dec 2008) | 2 lines
#4446: document "platforms" argument for setup().
........
r67785 | georg.brandl | 2008-12-15 02:36:11 -0600 (Mon, 15 Dec 2008) | 2 lines
#4611: fix typo.
........
r67787 | georg.brandl | 2008-12-15 02:58:59 -0600 (Mon, 15 Dec 2008) | 2 lines
#4578: fix has_key() usage in compiler package.
........
r67788 | georg.brandl | 2008-12-15 03:07:39 -0600 (Mon, 15 Dec 2008) | 2 lines
#4568: remove limitation in varargs callback example.
........
r67802 | amaury.forgeotdarc | 2008-12-15 16:29:14 -0600 (Mon, 15 Dec 2008) | 4 lines
#3632: the "pyo" macro from gdbinit can now run when the GIL is released.
Patch by haypo.
........
r67848 | benjamin.peterson | 2008-12-18 20:28:56 -0600 (Thu, 18 Dec 2008) | 1 line
fix typo
........
r67849 | benjamin.peterson | 2008-12-18 20:31:35 -0600 (Thu, 18 Dec 2008) | 1 line
_call_method -> _callmethod and _get_value to _getvalue
........
r67850 | raymond.hettinger | 2008-12-19 03:06:07 -0600 (Fri, 19 Dec 2008) | 9 lines
Fix-up and clean-up docs for int.bit_length().
* Replace dramatic footnote with in-line comment about possible round-off errors in logarithms of large numbers.
* Add comments to the pure python code equivalent.
* replace floor() with int() in the mathematical equivalent so the type is correct (should be an int, not a float).
* add abs() to the mathematical equivalent so that it matches the previous line that it is supposed to be equivalent to.
* make one combined example with a negative input.
........
r67862 | benjamin.peterson | 2008-12-19 20:48:02 -0600 (Fri, 19 Dec 2008) | 1 line
copy sentence from docstring
........
r67863 | benjamin.peterson | 2008-12-19 20:51:26 -0600 (Fri, 19 Dec 2008) | 1 line
add headings
........
r67864 | benjamin.peterson | 2008-12-19 20:57:19 -0600 (Fri, 19 Dec 2008) | 1 line
beef up docstring
........
r67880 | benjamin.peterson | 2008-12-20 16:49:24 -0600 (Sat, 20 Dec 2008) | 1 line
remove redundant sentence
........
r67882 | benjamin.peterson | 2008-12-20 16:59:49 -0600 (Sat, 20 Dec 2008) | 1 line
add some recent releases to the list
........
2008-12-20 20:06:59 -04:00
|
|
|
eggs = _temp.eggs
|
|
|
|
saus = _temp.sausage
|
|
|
|
|
|
|
|
Here, the ``spam.ham`` module is returned from :func:`__import__`. From this
|
|
|
|
object, the names to import are retrieved and assigned to their respective
|
|
|
|
names.
|
|
|
|
|
|
|
|
If you simply want to import a module (potentially within a package) by name,
|
2011-07-29 12:50:58 -03:00
|
|
|
use :func:`importlib.import_module`.
|
|
|
|
|
2012-07-30 19:35:17 -03:00
|
|
|
.. versionchanged:: 3.3
|
2012-08-05 21:49:53 -03:00
|
|
|
Negative values for *level* are no longer supported (which also changes
|
|
|
|
the default value to 0).
|
2012-07-30 19:35:17 -03:00
|
|
|
|
2020-03-09 08:57:53 -03:00
|
|
|
.. versionchanged:: 3.9
|
|
|
|
When the command line options :option:`-E` or :option:`-I` are being used,
|
|
|
|
the environment variable :envvar:`PYTHONCASEOK` is now ignored.
|
2008-12-05 11:55:41 -04:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. rubric:: Footnotes
|
|
|
|
|
2009-03-31 13:57:13 -03:00
|
|
|
.. [#] Note that the parser only accepts the Unix-style end of line convention.
|
|
|
|
If you are reading the code from a file, make sure to use newline conversion
|
|
|
|
mode to convert Windows or Mac-style newlines.
|