Kaydet (Commit) ddca9f08 authored tarafından Mark Summerfield's avatar Mark Summerfield

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().
üst 0dda1e9e
...@@ -7,8 +7,9 @@ ...@@ -7,8 +7,9 @@
.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org> .. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
This module implements a helper class and functions to quickly write a loop over This module implements a helper class and functions to quickly write a
standard input or a list of files. 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:: The typical use is::
......
...@@ -765,7 +765,8 @@ available. They are listed here in alphabetical order. ...@@ -765,7 +765,8 @@ available. They are listed here in alphabetical order.
Python enforces that the mode, after stripping ``'U'``, begins with ``'r'``, Python enforces that the mode, after stripping ``'U'``, begins with ``'r'``,
``'w'`` or ``'a'``. ``'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 .. versionchanged:: 2.5
Restriction on first letter of mode string introduced. Restriction on first letter of mode string introduced.
......
...@@ -48,18 +48,18 @@ The logical operations are also generally applicable to all objects, and support ...@@ -48,18 +48,18 @@ The logical operations are also generally applicable to all objects, and support
truth tests, identity tests, and boolean operations: truth tests, identity tests, and boolean operations:
.. function:: not_(o) .. function:: not_(obj)
__not__(o) __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 :meth:`__not__` method for object instances; only the interpreter core defines
this operation. The result is affected by the :meth:`__nonzero__` and this operation. The result is affected by the :meth:`__nonzero__` and
:meth:`__len__` methods.) :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. equivalent to using the :class:`bool` constructor.
...@@ -79,10 +79,10 @@ truth tests, identity tests, and boolean operations: ...@@ -79,10 +79,10 @@ truth tests, identity tests, and boolean operations:
The mathematical and bitwise operations are the most numerous: The mathematical and bitwise operations are the most numerous:
.. function:: abs(o) .. function:: abs(obj)
__abs__(o) __abs__(obj)
Return the absolute value of *o*. Return the absolute value of *obj*.
.. function:: add(a, b) .. function:: add(a, b)
...@@ -112,12 +112,12 @@ The mathematical and bitwise operations are the most numerous: ...@@ -112,12 +112,12 @@ The mathematical and bitwise operations are the most numerous:
.. versionadded:: 2.2 .. versionadded:: 2.2
.. function:: inv(o) .. function:: inv(obj)
invert(o) invert(obj)
__inv__(o) __inv__(obj)
__invert__(o) __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 .. versionadded:: 2.0
The names :func:`invert` and :func:`__invert__`. The names :func:`invert` and :func:`__invert__`.
...@@ -141,10 +141,10 @@ The mathematical and bitwise operations are the most numerous: ...@@ -141,10 +141,10 @@ The mathematical and bitwise operations are the most numerous:
Return ``a * b``, for *a* and *b* numbers. Return ``a * b``, for *a* and *b* numbers.
.. function:: neg(o) .. function:: neg(obj)
__neg__(o) __neg__(obj)
Return *o* negated. Return *obj* negated.
.. function:: or_(a, b) .. function:: or_(a, b)
...@@ -153,10 +153,10 @@ The mathematical and bitwise operations are the most numerous: ...@@ -153,10 +153,10 @@ The mathematical and bitwise operations are the most numerous:
Return the bitwise or of *a* and *b*. Return the bitwise or of *a* and *b*.
.. function:: pos(o) .. function:: pos(obj)
__pos__(o) __pos__(obj)
Return *o* positive. Return *obj* positive.
.. function:: pow(a, b) .. function:: pow(a, b)
...@@ -421,24 +421,30 @@ objects. ...@@ -421,24 +421,30 @@ objects.
... pass ... pass
... ...
>>> import operator >>> import operator
>>> o = C() >>> obj = C()
>>> operator.isMappingType(o) >>> operator.isMappingType(obj)
True True
.. note::
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(o) .. function:: isCallable(obj)
.. deprecated:: 2.0 .. deprecated:: 2.0
Use the :func:`callable` built-in function instead. 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 returns false. True is returned for functions, bound and unbound methods, class
objects, and instance objects which support the :meth:`__call__` method. 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__`. dictionaries and all instance objects defining :meth:`__getitem__`.
.. warning:: .. warning::
...@@ -448,9 +454,9 @@ objects. ...@@ -448,9 +454,9 @@ objects.
useful than it otherwise might be. 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. numeric types implemented in C.
.. warning:: .. warning::
...@@ -460,9 +466,9 @@ objects. ...@@ -460,9 +466,9 @@ objects.
useful than it otherwise might be. 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 for all objects which define sequence methods in C, and for all instance objects
defining :meth:`__getitem__`. defining :meth:`__getitem__`.
...@@ -541,7 +547,7 @@ Python syntax and the functions in the :mod:`operator` module. ...@@ -541,7 +547,7 @@ Python syntax and the functions in the :mod:`operator` module.
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------+
| Concatenation | ``seq1 + seq2`` | ``concat(seq1, seq2)`` | | 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 | | Division | ``a / b`` | ``div(a, b)`` (without |
| | | ``__future__.division``) | | | | ``__future__.division``) |
...@@ -565,11 +571,11 @@ Python syntax and the functions in the :mod:`operator` module. ...@@ -565,11 +571,11 @@ Python syntax and the functions in the :mod:`operator` module.
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------+
| Identity | ``a is not b`` | ``is_not(a, b)`` | | 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)`` | | Left Shift | ``a << b`` | ``lshift(a, b)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------+
...@@ -591,11 +597,11 @@ Python syntax and the functions in the :mod:`operator` module. ...@@ -591,11 +597,11 @@ Python syntax and the functions in the :mod:`operator` module.
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------+
| Slicing | ``seq[i:j]`` | ``getslice(seq, i, j)`` | | 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)`` | | Subtraction | ``a - b`` | ``sub(a, b)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------+
| Truth Test | ``o`` | ``truth(o)`` | | Truth Test | ``obj`` | ``truth(obj)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------+
| Ordering | ``a < b`` | ``lt(a, b)`` | | Ordering | ``a < b`` | ``lt(a, b)`` |
+-----------------------+-------------------------+---------------------------------+ +-----------------------+-------------------------+---------------------------------+
......
...@@ -8,9 +8,10 @@ ...@@ -8,9 +8,10 @@
This module provides a more portable way of using operating system dependent This module provides a more portable way of using operating system dependent
functionality than importing a operating system dependent built-in module like 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 :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` :func:`open`, if you want to manipulate paths, see the :mod:`os.path`
module.) 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 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 :mod:`mac` or :mod:`posix` and exports the same functions and data as found
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment