mirror of
https://github.com/python/cpython.git
synced 2025-07-29 14:15:07 +00:00
Replaced variable o with obj in operator.rst because o is easy to
confuse. Added a note about Python 3's collections.Mapping etc., above section that describes isMappingType() etc. Added xrefs between os, os.path, fileinput, and open().
This commit is contained in:
parent
0dda1e9e94
commit
ddca9f0823
4 changed files with 50 additions and 41 deletions
|
@ -7,8 +7,9 @@
|
|||
.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
|
||||
|
||||
|
||||
This module implements a helper class and functions to quickly write a loop over
|
||||
standard input or a list of files.
|
||||
This module implements a helper class and functions to quickly write a
|
||||
loop over standard input or a list of files. If you just want to read or
|
||||
write one file see :func:`open`.
|
||||
|
||||
The typical use is::
|
||||
|
||||
|
|
|
@ -765,7 +765,8 @@ available. They are listed here in alphabetical order.
|
|||
Python enforces that the mode, after stripping ``'U'``, begins with ``'r'``,
|
||||
``'w'`` or ``'a'``.
|
||||
|
||||
See also the :mod:`fileinput` module.
|
||||
See also the :mod:`fileinput` module, the :mod:`os` module, and the
|
||||
:mod:`os.path` module.
|
||||
|
||||
.. versionchanged:: 2.5
|
||||
Restriction on first letter of mode string introduced.
|
||||
|
|
|
@ -48,18 +48,18 @@ The logical operations are also generally applicable to all objects, and support
|
|||
truth tests, identity tests, and boolean operations:
|
||||
|
||||
|
||||
.. function:: not_(o)
|
||||
__not__(o)
|
||||
.. function:: not_(obj)
|
||||
__not__(obj)
|
||||
|
||||
Return the outcome of :keyword:`not` *o*. (Note that there is no
|
||||
Return the outcome of :keyword:`not` *obj*. (Note that there is no
|
||||
:meth:`__not__` method for object instances; only the interpreter core defines
|
||||
this operation. The result is affected by the :meth:`__nonzero__` and
|
||||
:meth:`__len__` methods.)
|
||||
|
||||
|
||||
.. function:: truth(o)
|
||||
.. function:: truth(obj)
|
||||
|
||||
Return :const:`True` if *o* is true, and :const:`False` otherwise. This is
|
||||
Return :const:`True` if *obj* is true, and :const:`False` otherwise. This is
|
||||
equivalent to using the :class:`bool` constructor.
|
||||
|
||||
|
||||
|
@ -79,10 +79,10 @@ truth tests, identity tests, and boolean operations:
|
|||
The mathematical and bitwise operations are the most numerous:
|
||||
|
||||
|
||||
.. function:: abs(o)
|
||||
__abs__(o)
|
||||
.. function:: abs(obj)
|
||||
__abs__(obj)
|
||||
|
||||
Return the absolute value of *o*.
|
||||
Return the absolute value of *obj*.
|
||||
|
||||
|
||||
.. function:: add(a, b)
|
||||
|
@ -112,12 +112,12 @@ The mathematical and bitwise operations are the most numerous:
|
|||
.. versionadded:: 2.2
|
||||
|
||||
|
||||
.. function:: inv(o)
|
||||
invert(o)
|
||||
__inv__(o)
|
||||
__invert__(o)
|
||||
.. function:: inv(obj)
|
||||
invert(obj)
|
||||
__inv__(obj)
|
||||
__invert__(obj)
|
||||
|
||||
Return the bitwise inverse of the number *o*. This is equivalent to ``~o``.
|
||||
Return the bitwise inverse of the number *obj*. This is equivalent to ``~obj``.
|
||||
|
||||
.. versionadded:: 2.0
|
||||
The names :func:`invert` and :func:`__invert__`.
|
||||
|
@ -141,10 +141,10 @@ The mathematical and bitwise operations are the most numerous:
|
|||
Return ``a * b``, for *a* and *b* numbers.
|
||||
|
||||
|
||||
.. function:: neg(o)
|
||||
__neg__(o)
|
||||
.. function:: neg(obj)
|
||||
__neg__(obj)
|
||||
|
||||
Return *o* negated.
|
||||
Return *obj* negated.
|
||||
|
||||
|
||||
.. function:: or_(a, b)
|
||||
|
@ -153,10 +153,10 @@ The mathematical and bitwise operations are the most numerous:
|
|||
Return the bitwise or of *a* and *b*.
|
||||
|
||||
|
||||
.. function:: pos(o)
|
||||
__pos__(o)
|
||||
.. function:: pos(obj)
|
||||
__pos__(obj)
|
||||
|
||||
Return *o* positive.
|
||||
Return *obj* positive.
|
||||
|
||||
|
||||
.. function:: pow(a, b)
|
||||
|
@ -421,24 +421,30 @@ objects.
|
|||
... pass
|
||||
...
|
||||
>>> import operator
|
||||
>>> o = C()
|
||||
>>> operator.isMappingType(o)
|
||||
>>> obj = C()
|
||||
>>> operator.isMappingType(obj)
|
||||
True
|
||||
|
||||
.. note::
|
||||
|
||||
.. function:: isCallable(o)
|
||||
Python 3 is expected to introduce abstract base classes for
|
||||
collection types, so it should be possible to write, for example,
|
||||
``isinstance(obj, collections.Mapping)`` and ``isinstance(obj,
|
||||
collections.Sequence)``.
|
||||
|
||||
.. function:: isCallable(obj)
|
||||
|
||||
.. deprecated:: 2.0
|
||||
Use the :func:`callable` built-in function instead.
|
||||
|
||||
Returns true if the object *o* can be called like a function, otherwise it
|
||||
Returns true if the object *obj* can be called like a function, otherwise it
|
||||
returns false. True is returned for functions, bound and unbound methods, class
|
||||
objects, and instance objects which support the :meth:`__call__` method.
|
||||
|
||||
|
||||
.. function:: isMappingType(o)
|
||||
.. function:: isMappingType(obj)
|
||||
|
||||
Returns true if the object *o* supports the mapping interface. This is true for
|
||||
Returns true if the object *obj* supports the mapping interface. This is true for
|
||||
dictionaries and all instance objects defining :meth:`__getitem__`.
|
||||
|
||||
.. warning::
|
||||
|
@ -448,9 +454,9 @@ objects.
|
|||
useful than it otherwise might be.
|
||||
|
||||
|
||||
.. function:: isNumberType(o)
|
||||
.. function:: isNumberType(obj)
|
||||
|
||||
Returns true if the object *o* represents a number. This is true for all
|
||||
Returns true if the object *obj* represents a number. This is true for all
|
||||
numeric types implemented in C.
|
||||
|
||||
.. warning::
|
||||
|
@ -460,9 +466,9 @@ objects.
|
|||
useful than it otherwise might be.
|
||||
|
||||
|
||||
.. function:: isSequenceType(o)
|
||||
.. function:: isSequenceType(obj)
|
||||
|
||||
Returns true if the object *o* supports the sequence protocol. This returns true
|
||||
Returns true if the object *obj* supports the sequence protocol. This returns true
|
||||
for all objects which define sequence methods in C, and for all instance objects
|
||||
defining :meth:`__getitem__`.
|
||||
|
||||
|
@ -541,7 +547,7 @@ Python syntax and the functions in the :mod:`operator` module.
|
|||
+-----------------------+-------------------------+---------------------------------+
|
||||
| Concatenation | ``seq1 + seq2`` | ``concat(seq1, seq2)`` |
|
||||
+-----------------------+-------------------------+---------------------------------+
|
||||
| Containment Test | ``o in seq`` | ``contains(seq, o)`` |
|
||||
| Containment Test | ``obj in seq`` | ``contains(seq, obj)`` |
|
||||
+-----------------------+-------------------------+---------------------------------+
|
||||
| Division | ``a / b`` | ``div(a, b)`` (without |
|
||||
| | | ``__future__.division``) |
|
||||
|
@ -565,11 +571,11 @@ Python syntax and the functions in the :mod:`operator` module.
|
|||
+-----------------------+-------------------------+---------------------------------+
|
||||
| Identity | ``a is not b`` | ``is_not(a, b)`` |
|
||||
+-----------------------+-------------------------+---------------------------------+
|
||||
| Indexed Assignment | ``o[k] = v`` | ``setitem(o, k, v)`` |
|
||||
| Indexed Assignment | ``obj[k] = v`` | ``setitem(obj, k, v)`` |
|
||||
+-----------------------+-------------------------+---------------------------------+
|
||||
| Indexed Deletion | ``del o[k]`` | ``delitem(o, k)`` |
|
||||
| Indexed Deletion | ``del obj[k]`` | ``delitem(obj, k)`` |
|
||||
+-----------------------+-------------------------+---------------------------------+
|
||||
| Indexing | ``o[k]`` | ``getitem(o, k)`` |
|
||||
| Indexing | ``obj[k]`` | ``getitem(obj, k)`` |
|
||||
+-----------------------+-------------------------+---------------------------------+
|
||||
| Left Shift | ``a << b`` | ``lshift(a, b)`` |
|
||||
+-----------------------+-------------------------+---------------------------------+
|
||||
|
@ -591,11 +597,11 @@ Python syntax and the functions in the :mod:`operator` module.
|
|||
+-----------------------+-------------------------+---------------------------------+
|
||||
| Slicing | ``seq[i:j]`` | ``getslice(seq, i, j)`` |
|
||||
+-----------------------+-------------------------+---------------------------------+
|
||||
| String Formatting | ``s % o`` | ``mod(s, o)`` |
|
||||
| String Formatting | ``s % obj`` | ``mod(s, obj)`` |
|
||||
+-----------------------+-------------------------+---------------------------------+
|
||||
| Subtraction | ``a - b`` | ``sub(a, b)`` |
|
||||
+-----------------------+-------------------------+---------------------------------+
|
||||
| Truth Test | ``o`` | ``truth(o)`` |
|
||||
| Truth Test | ``obj`` | ``truth(obj)`` |
|
||||
+-----------------------+-------------------------+---------------------------------+
|
||||
| Ordering | ``a < b`` | ``lt(a, b)`` |
|
||||
+-----------------------+-------------------------+---------------------------------+
|
||||
|
|
|
@ -8,9 +8,10 @@
|
|||
|
||||
This module provides a more portable way of using operating system dependent
|
||||
functionality than importing a operating system dependent built-in module like
|
||||
:mod:`posix` or :mod:`nt`. (If you just want to read or write a file see
|
||||
:func:`open`, and if you want to manipulate paths, see the :mod:`os.path`
|
||||
module.)
|
||||
:mod:`posix` or :mod:`nt`. If you just want to read or write a file see
|
||||
:func:`open`, if you want to manipulate paths, see the :mod:`os.path`
|
||||
module, and if you want to read all the lines in all the files on the
|
||||
command line see the :mod:`fileinput` module.
|
||||
|
||||
This module searches for an operating system dependent built-in module like
|
||||
:mod:`mac` or :mod:`posix` and exports the same functions and data as found
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue