Commit 11cb961b authored by Antoine Pitrou's avatar Antoine Pitrou

Add cross-references to the glossary entry for file objects.

parent 6a11a98b
...@@ -210,8 +210,8 @@ have to remember to change two places in your program -- the second occurrence ...@@ -210,8 +210,8 @@ have to remember to change two places in your program -- the second occurrence
is hidden at the bottom of the loop. is hidden at the bottom of the loop.
The best approach is to use iterators, making it possible to loop through The best approach is to use iterators, making it possible to loop through
objects using the ``for`` statement. For example, in the current version of objects using the ``for`` statement. For example, :term:`file objects
Python file objects support the iterator protocol, so you can now write simply:: <file object>` support the iterator protocol, so you can write simply::
for line in f: for line in f:
... # do something with line... ... # do something with line...
......
...@@ -40,10 +40,10 @@ Module :mod:`aifc` defines the following function: ...@@ -40,10 +40,10 @@ Module :mod:`aifc` defines the following function:
.. function:: open(file, mode=None) .. function:: open(file, mode=None)
Open an AIFF or AIFF-C file and return an object instance with methods that are Open an AIFF or AIFF-C file and return an object instance with methods that are
described below. The argument *file* is either a string naming a file or a file described below. The argument *file* is either a string naming a file or a
object. *mode* must be ``'r'`` or ``'rb'`` when the file must be opened for :term:`file object`. *mode* must be ``'r'`` or ``'rb'`` when the file must be
reading, or ``'w'`` or ``'wb'`` when the file must be opened for writing. If opened for reading, or ``'w'`` or ``'wb'`` when the file must be opened for writing.
omitted, ``file.mode`` is used if it exists, otherwise ``'rb'`` is used. When If omitted, ``file.mode`` is used if it exists, otherwise ``'rb'`` is used. When
used for writing, the file object should be seekable, unless you know ahead of used for writing, the file object should be seekable, unless you know ahead of
time how many samples you are going to write in total and use time how many samples you are going to write in total and use
:meth:`writeframesraw` and :meth:`setnframes`. :meth:`writeframesraw` and :meth:`setnframes`.
......
...@@ -147,11 +147,11 @@ The following data items and methods are also supported: ...@@ -147,11 +147,11 @@ The following data items and methods are also supported:
.. method:: array.fromfile(f, n) .. method:: array.fromfile(f, n)
Read *n* items (as machine values) from the file object *f* and append them to Read *n* items (as machine values) from the :term:`file object` *f* and append
the end of the array. If less than *n* items are available, :exc:`EOFError` is them to the end of the array. If less than *n* items are available,
raised, but the items that were available are still inserted into the array. :exc:`EOFError` is raised, but the items that were available are still
*f* must be a real built-in file object; something else with a :meth:`read` inserted into the array. *f* must be a real built-in file object; something
method won't do. else with a :meth:`read` method won't do.
.. method:: array.fromlist(list) .. method:: array.fromlist(list)
...@@ -214,7 +214,7 @@ The following data items and methods are also supported: ...@@ -214,7 +214,7 @@ The following data items and methods are also supported:
.. method:: array.tofile(f) .. method:: array.tofile(f)
Write all items (as machine values) to the file object *f*. Write all items (as machine values) to the :term:`file object` *f*.
.. method:: array.tolist() .. method:: array.tolist()
......
...@@ -225,9 +225,9 @@ any that have been added to the map during asynchronous service) is closed. ...@@ -225,9 +225,9 @@ any that have been added to the map during asynchronous service) is closed.
.. class:: file_dispatcher() .. class:: file_dispatcher()
A file_dispatcher takes a file descriptor or file object along with an A file_dispatcher takes a file descriptor or :term:`file object` along
optional map argument and wraps it for use with the :cfunc:`poll` or with an optional map argument and wraps it for use with the :cfunc:`poll`
:cfunc:`loop` functions. If provided a file object or anything with a or :cfunc:`loop` functions. If provided a file object or anything with a
:cfunc:`fileno` method, that method will be called and passed to the :cfunc:`fileno` method, that method will be called and passed to the
:class:`file_wrapper` constructor. Availability: UNIX. :class:`file_wrapper` constructor. Availability: UNIX.
......
...@@ -122,9 +122,9 @@ The legacy interface: ...@@ -122,9 +122,9 @@ The legacy interface:
.. function:: decode(input, output) .. function:: decode(input, output)
Decode the contents of the binary *input* file and write the resulting binary Decode the contents of the binary *input* file and write the resulting binary
data to the *output* file. *input* and *output* must either be file objects data to the *output* file. *input* and *output* must be :term:`file objects
or objects that mimic the file object interface working with bytes <file object>`. *input* will be read until ``input.read()`` returns an empty
objects. *input* will be read until ``input.read()`` returns an empty string. bytes object.
.. function:: decodebytes(s) .. function:: decodebytes(s)
...@@ -138,11 +138,10 @@ The legacy interface: ...@@ -138,11 +138,10 @@ The legacy interface:
.. function:: encode(input, output) .. function:: encode(input, output)
Encode the contents of the binary *input* file and write the resulting base64 Encode the contents of the binary *input* file and write the resulting base64
encoded data to the *output* file. *input* and *output* must either be file encoded data to the *output* file. *input* and *output* must be :term:`file
objects or objects that mimic the file object interface working with bytes objects <file object>`. *input* will be read until ``input.read()`` returns
objects. *input* will be read until ``input.read()`` returns an empty string. an empty bytes object. :func:`encode` returns the encoded data plus a trailing
:func:`encode` returns the encoded data plus a trailing newline character newline character (``b'\n'``).
(``b'\n'``).
.. function:: encodebytes(s) .. function:: encodebytes(s)
......
...@@ -25,8 +25,8 @@ Here is a summary of the features offered by the bz2 module: ...@@ -25,8 +25,8 @@ Here is a summary of the features offered by the bz2 module:
* :class:`BZ2File` class implements universal newline support; * :class:`BZ2File` class implements universal newline support;
* :class:`BZ2File` class offers an optimized line iteration using the readahead * :class:`BZ2File` class offers an optimized line iteration using a readahead
algorithm borrowed from file objects; algorithm;
* Sequential (de)compression supported by :class:`BZ2Compressor` and * Sequential (de)compression supported by :class:`BZ2Compressor` and
:class:`BZ2Decompressor` classes; :class:`BZ2Decompressor` classes;
......
...@@ -422,7 +422,7 @@ RawConfigParser Objects ...@@ -422,7 +422,7 @@ RawConfigParser Objects
.. method:: RawConfigParser.write(fileobject, space_around_delimiters=True) .. method:: RawConfigParser.write(fileobject, space_around_delimiters=True)
Write a representation of the configuration to the specified file object, Write a representation of the configuration to the specified :term:`file object`,
which must be opened in text mode (accepting strings). This representation which must be opened in text mode (accepting strings). This representation
can be parsed by a future :meth:`read` call. If ``space_around_delimiters`` can be parsed by a future :meth:`read` call. If ``space_around_delimiters``
is ``True`` (the default), delimiters between keys and values are surrounded is ``True`` (the default), delimiters between keys and values are surrounded
......
...@@ -50,9 +50,9 @@ The :mod:`csv` module defines the following functions: ...@@ -50,9 +50,9 @@ The :mod:`csv` module defines the following functions:
Return a reader object which will iterate over lines in the given *csvfile*. Return a reader object which will iterate over lines in the given *csvfile*.
*csvfile* can be any object which supports the :term:`iterator` protocol and returns a *csvfile* can be any object which supports the :term:`iterator` protocol and returns a
string each time its :meth:`!next` method is called --- file objects and list string each time its :meth:`!next` method is called --- :term:`file objects
objects are both suitable. If *csvfile* is a file object, it should be opened <file object>` and list objects are both suitable. If *csvfile* is a file object,
with ``newline=''``. [#]_ An optional it should be opened with ``newline=''``. [#]_ An optional
*dialect* parameter can be given which is used to define a set of parameters *dialect* parameter can be given which is used to define a set of parameters
specific to a particular CSV dialect. It may be an instance of a subclass of specific to a particular CSV dialect. It may be an instance of a subclass of
the :class:`Dialect` class or one of the strings returned by the the :class:`Dialect` class or one of the strings returned by the
......
...@@ -28,9 +28,9 @@ Here are the public methods of the :class:`Generator` class, imported from the ...@@ -28,9 +28,9 @@ Here are the public methods of the :class:`Generator` class, imported from the
.. class:: Generator(outfp, mangle_from_=True, maxheaderlen=78) .. class:: Generator(outfp, mangle_from_=True, maxheaderlen=78)
The constructor for the :class:`Generator` class takes a file-like object called The constructor for the :class:`Generator` class takes a :term:`file-like object`
*outfp* for an argument. *outfp* must support the :meth:`write` method and be called *outfp* for an argument. *outfp* must support the :meth:`write` method
usable as the output file for the :func:`print` function. and be usable as the output file for the :func:`print` function.
Optional *mangle_from_* is a flag that, when ``True``, puts a ``>`` character in Optional *mangle_from_* is a flag that, when ``True``, puts a ``>`` character in
front of any line in the body that starts exactly as ``From``, i.e. ``From`` front of any line in the body that starts exactly as ``From``, i.e. ``From``
......
...@@ -154,9 +154,9 @@ in the top-level :mod:`email` package namespace. ...@@ -154,9 +154,9 @@ in the top-level :mod:`email` package namespace.
.. function:: message_from_file(fp[, _class][, strict]) .. function:: message_from_file(fp[, _class][, strict])
Return a message object structure tree from an open file object. This is Return a message object structure tree from an open :term:`file object`.
exactly equivalent to ``Parser().parse(fp)``. Optional *_class* and *strict* This is exactly equivalent to ``Parser().parse(fp)``. Optional *_class*
are interpreted as with the :class:`Parser` class constructor. and *strict* are interpreted as with the :class:`Parser` class constructor.
Here's an example of how you might use this at an interactive Python prompt:: Here's an example of how you might use this at an interactive Python prompt::
......
...@@ -134,8 +134,8 @@ The following exceptions are the exceptions that are usually raised. ...@@ -134,8 +134,8 @@ The following exceptions are the exceptions that are usually raised.
.. exception:: IOError .. exception:: IOError
Raised when an I/O operation (such as the built-in :func:`print` or Raised when an I/O operation (such as the built-in :func:`print` or
:func:`open` functions or a method of a file object) fails for an I/O-related :func:`open` functions or a method of a :term:`file object`) fails for an
reason, e.g., "file not found" or "disk full". I/O-related reason, e.g., "file not found" or "disk full".
This class is derived from :exc:`EnvironmentError`. See the discussion above This class is derived from :exc:`EnvironmentError`. See the discussion above
for more information on exception instance attributes. for more information on exception instance attributes.
......
...@@ -27,8 +27,8 @@ in this chapter is: ...@@ -27,8 +27,8 @@ in this chapter is:
.. seealso:: .. seealso::
Module :mod:`os` Module :mod:`os`
Operating system interfaces, including functions to work with files at a lower Operating system interfaces, including functions to work with files at a
level than the built-in file object. lower level than Python :term:`file objects <file object>`.
Module :mod:`io` Module :mod:`io`
Python's built-in I/O library, including both abstract classes and Python's built-in I/O library, including both abstract classes and
......
...@@ -339,8 +339,8 @@ this module. Most applications will need to derive new writer classes from the ...@@ -339,8 +339,8 @@ this module. Most applications will need to derive new writer classes from the
.. class:: DumbWriter(file=None, maxcol=72) .. class:: DumbWriter(file=None, maxcol=72)
Simple writer class which writes output on the file object passed in as *file* Simple writer class which writes output on the :term:`file object` passed
or, if *file* is omitted, on standard output. The output is simply word-wrapped in as *file* or, if *file* is omitted, on standard output. The output is
to the number of columns specified by *maxcol*. This class is suitable for simply word-wrapped to the number of columns specified by *maxcol*. This
reflowing a sequence of paragraphs. class is suitable for reflowing a sequence of paragraphs.
...@@ -245,12 +245,12 @@ followed by ``lines`` for the text version or ``binary`` for the binary version. ...@@ -245,12 +245,12 @@ followed by ``lines`` for the text version or ``binary`` for the binary version.
.. method:: FTP.storbinary(cmd, file, blocksize=8192, callback=None, rest=None) .. method:: FTP.storbinary(cmd, file, blocksize=8192, callback=None, rest=None)
Store a file in binary transfer mode. *cmd* should be an appropriate Store a file in binary transfer mode. *cmd* should be an appropriate
``STOR`` command: ``"STOR filename"``. *file* is an open file object which is ``STOR`` command: ``"STOR filename"``. *file* is an open :term:`file object`
read until EOF using its :meth:`read` method in blocks of size *blocksize* to which is read until EOF using its :meth:`read` method in blocks of size
provide the data to be stored. The *blocksize* argument defaults to 8192. *blocksize* to provide the data to be stored. The *blocksize* argument
*callback* is an optional single parameter callable that is called defaults to 8192. *callback* is an optional single parameter callable that
on each block of data after it is sent. *rest* means the same thing as in is called on each block of data after it is sent. *rest* means the same thing
the :meth:`transfercmd` method. as in the :meth:`transfercmd` method.
.. versionchanged:: 3.2 .. versionchanged:: 3.2
*rest* parameter added. *rest* parameter added.
...@@ -260,8 +260,8 @@ followed by ``lines`` for the text version or ``binary`` for the binary version. ...@@ -260,8 +260,8 @@ followed by ``lines`` for the text version or ``binary`` for the binary version.
Store a file in ASCII transfer mode. *cmd* should be an appropriate Store a file in ASCII transfer mode. *cmd* should be an appropriate
``STOR`` command (see :meth:`storbinary`). Lines are read until EOF from the ``STOR`` command (see :meth:`storbinary`). Lines are read until EOF from the
open file object *file* using its :meth:`readline` method to provide the data to open :term:`file object` *file* using its :meth:`readline` method to provide
be stored. *callback* is an optional single parameter callable the data to be stored. *callback* is an optional single parameter callable
that is called on each line after it is sent. that is called on each line after it is sent.
......
...@@ -173,8 +173,8 @@ class can also install themselves in the built-in namespace as the function ...@@ -173,8 +173,8 @@ class can also install themselves in the built-in namespace as the function
associated :file:`.mo` file paths. Instances with identical :file:`.mo` file associated :file:`.mo` file paths. Instances with identical :file:`.mo` file
names are cached. The actual class instantiated is either *class_* if names are cached. The actual class instantiated is either *class_* if
provided, otherwise :class:`GNUTranslations`. The class's constructor must provided, otherwise :class:`GNUTranslations`. The class's constructor must
take a single file object argument. If provided, *codeset* will change the take a single :term:`file object` argument. If provided, *codeset* will change
charset used to encode translated strings in the :meth:`lgettext` and the charset used to encode translated strings in the :meth:`lgettext` and
:meth:`lngettext` methods. :meth:`lngettext` methods.
If multiple files are found, later files are used as fallbacks for earlier ones. If multiple files are found, later files are used as fallbacks for earlier ones.
...@@ -219,7 +219,7 @@ are the methods of :class:`NullTranslations`: ...@@ -219,7 +219,7 @@ are the methods of :class:`NullTranslations`:
.. class:: NullTranslations(fp=None) .. class:: NullTranslations(fp=None)
Takes an optional file object *fp*, which is ignored by the base class. Takes an optional :term:`file object` *fp*, which is ignored by the base class.
Initializes "protected" instance variables *_info* and *_charset* which are set Initializes "protected" instance variables *_info* and *_charset* which are set
by derived classes, as well as *_fallback*, which is set through by derived classes, as well as *_fallback*, which is set through
:meth:`add_fallback`. It then calls ``self._parse(fp)`` if *fp* is not :meth:`add_fallback`. It then calls ``self._parse(fp)`` if *fp* is not
......
...@@ -9,10 +9,9 @@ like the GNU programs :program:`gzip` and :program:`gunzip` would. ...@@ -9,10 +9,9 @@ like the GNU programs :program:`gzip` and :program:`gunzip` would.
The data compression is provided by the :mod:`zlib` module. The data compression is provided by the :mod:`zlib` module.
The :mod:`gzip` module provides the :class:`GzipFile` class which is modeled The :mod:`gzip` module provides the :class:`GzipFile` class. The :class:`GzipFile`
after Python's File Object. The :class:`GzipFile` class reads and writes class reads and writes :program:`gzip`\ -format files, automatically compressing
:program:`gzip`\ -format files, automatically compressing or decompressing the or decompressing the data so that it looks like an ordinary :term:`file object`.
data so that it looks like an ordinary file object.
Note that additional file formats which can be decompressed by the Note that additional file formats which can be decompressed by the
:program:`gzip` and :program:`gunzip` programs, such as those produced by :program:`gzip` and :program:`gunzip` programs, such as those produced by
...@@ -27,7 +26,7 @@ The module defines the following items: ...@@ -27,7 +26,7 @@ The module defines the following items:
.. class:: GzipFile(filename=None, mode=None, compresslevel=9, fileobj=None, mtime=None) .. class:: GzipFile(filename=None, mode=None, compresslevel=9, fileobj=None, mtime=None)
Constructor for the :class:`GzipFile` class, which simulates most of the methods Constructor for the :class:`GzipFile` class, which simulates most of the methods
of a file object, with the exception of the :meth:`readinto` and of a :term:`file object`, with the exception of the :meth:`readinto` and
:meth:`truncate` methods. At least one of *fileobj* and *filename* must be :meth:`truncate` methods. At least one of *fileobj* and *filename* must be
given a non-trivial value. given a non-trivial value.
......
...@@ -367,7 +367,7 @@ HTTPConnection Objects ...@@ -367,7 +367,7 @@ HTTPConnection Objects
object. The Content-Length header is set to the length of the object. The Content-Length header is set to the length of the
string. string.
The *body* may also be an open file object, in which case the The *body* may also be an open :term:`file object`, in which case the
contents of the file is sent; this file object should support contents of the file is sent; this file object should support
``fileno()`` and ``read()`` methods. The header Content-Length is ``fileno()`` and ``read()`` methods. The header Content-Length is
automatically set to the length of the file as reported by automatically set to the length of the file as reported by
......
...@@ -48,8 +48,8 @@ This module provides an interface to the mechanisms used to implement the ...@@ -48,8 +48,8 @@ This module provides an interface to the mechanisms used to implement the
If search is successful, the return value is a 3-element tuple ``(file, If search is successful, the return value is a 3-element tuple ``(file,
pathname, description)``: pathname, description)``:
*file* is an open file object positioned at the beginning, *pathname* is the *file* is an open :term:`file object` positioned at the beginning, *pathname*
pathname of the file found, and *description* is a 3-element tuple as is the pathname of the file found, and *description* is a 3-element tuple as
contained in the list returned by :func:`get_suffixes` describing the kind of contained in the list returned by :func:`get_suffixes` describing the kind of
module found. module found.
......
...@@ -5,14 +5,13 @@ ...@@ -5,14 +5,13 @@
:synopsis: Interface to memory-mapped files for Unix and Windows. :synopsis: Interface to memory-mapped files for Unix and Windows.
Memory-mapped file objects behave like both :class:`bytes` and like file Memory-mapped file objects behave like both :class:`bytearray` and like
objects. Unlike normal :class:`bytes` objects, however, these are mutable. :term:`file objects <file object>`. You can use mmap objects in most places
You can use mmap objects in most places where :class:`bytes` are expected; for where :class:`bytearray` are expected; for example, you can use the :mod:`re`
example, you can use the :mod:`re` module to search through a memory-mapped file. module to search through a memory-mapped file. You can also change a single
Since they're mutable, you can change a single byte by doing ``obj[index] = 97``, byte by doing ``obj[index] = 97``, or change a subsequence by assigning to a
or change a subsequence by assigning to a slice: ``obj[i1:i2] = b'...'``. slice: ``obj[i1:i2] = b'...'``. You can also read and write data starting at
You can also read and write data starting at the current file position, and the current file position, and :meth:`seek` through the file to different positions.
:meth:`seek` through the file to different positions.
A memory-mapped file is created by the :class:`mmap` constructor, which is A memory-mapped file is created by the :class:`mmap` constructor, which is
different on Unix and on Windows. In either case you must provide a file different on Unix and on Windows. In either case you must provide a file
......
...@@ -143,9 +143,9 @@ indicates an error, the method raises one of the above exceptions. ...@@ -143,9 +143,9 @@ indicates an error, the method raises one of the above exceptions.
*groups* is a list of group names that are new since the given date and time. If *groups* is a list of group names that are new since the given date and time. If
the *file* parameter is supplied, then the output of the ``NEWGROUPS`` command the *file* parameter is supplied, then the output of the ``NEWGROUPS`` command
is stored in a file. If *file* is a string, then the method will open a file is stored in a file. If *file* is a string, then the method will open a file
object with that name, write to it then close it. If *file* is a file object, object with that name, write to it then close it. If *file* is a :term:`file
then it will start calling :meth:`write` on it to store the lines of the command object`, then it will start calling :meth:`write` on it to store the lines of
output. If *file* is supplied, then the returned *list* is an empty list. the command output. If *file* is supplied, then the returned *list* is an empty list.
.. method:: NNTP.newnews(group, date, time, [file]) .. method:: NNTP.newnews(group, date, time, [file])
...@@ -155,9 +155,9 @@ indicates an error, the method raises one of the above exceptions. ...@@ -155,9 +155,9 @@ indicates an error, the method raises one of the above exceptions.
``(response, articles)`` where *articles* is a list of message ids. If the ``(response, articles)`` where *articles* is a list of message ids. If the
*file* parameter is supplied, then the output of the ``NEWNEWS`` command is *file* parameter is supplied, then the output of the ``NEWNEWS`` command is
stored in a file. If *file* is a string, then the method will open a file stored in a file. If *file* is a string, then the method will open a file
object with that name, write to it then close it. If *file* is a file object, object with that name, write to it then close it. If *file* is a :term:`file
then it will start calling :meth:`write` on it to store the lines of the command object`, then it will start calling :meth:`write` on it to store the lines of the
output. If *file* is supplied, then the returned *list* is an empty list. command output. If *file* is supplied, then the returned *list* is an empty list.
.. method:: NNTP.list([file]) .. method:: NNTP.list([file])
...@@ -169,9 +169,9 @@ indicates an error, the method raises one of the above exceptions. ...@@ -169,9 +169,9 @@ indicates an error, the method raises one of the above exceptions.
not, and ``'m'`` if the newsgroup is moderated. (Note the ordering: *last*, not, and ``'m'`` if the newsgroup is moderated. (Note the ordering: *last*,
*first*.) If the *file* parameter is supplied, then the output of the ``LIST`` *first*.) If the *file* parameter is supplied, then the output of the ``LIST``
command is stored in a file. If *file* is a string, then the method will open command is stored in a file. If *file* is a string, then the method will open
a file object with that name, write to it then close it. If *file* is a file a file with that name, write to it then close it. If *file* is a :term:`file
object, then it will start calling :meth:`write` on it to store the lines of the object`, then it will start calling :meth:`write` on it to store the lines of
command output. If *file* is supplied, then the returned *list* is an empty the command output. If *file* is supplied, then the returned *list* is an empty
list. list.
...@@ -207,8 +207,8 @@ indicates an error, the method raises one of the above exceptions. ...@@ -207,8 +207,8 @@ indicates an error, the method raises one of the above exceptions.
Send a ``HELP`` command. Return a pair ``(response, list)`` where *list* is a Send a ``HELP`` command. Return a pair ``(response, list)`` where *list* is a
list of help strings. If the *file* parameter is supplied, then the output of list of help strings. If the *file* parameter is supplied, then the output of
the ``HELP`` command is stored in a file. If *file* is a string, then the the ``HELP`` command is stored in a file. If *file* is a string, then the
method will open a file object with that name, write to it then close it. If method will open a file with that name, write to it then close it. If *file*
*file* is a file object, then it will start calling :meth:`write` on it to store is a :term:`file object`, then it will start calling :meth:`write` on it to store
the lines of the command output. If *file* is supplied, then the returned *list* the lines of the command output. If *file* is supplied, then the returned *list*
is an empty list. is an empty list.
...@@ -243,8 +243,8 @@ indicates an error, the method raises one of the above exceptions. ...@@ -243,8 +243,8 @@ indicates an error, the method raises one of the above exceptions.
Send a ``BODY`` command, where *id* has the same meaning as for :meth:`stat`. Send a ``BODY`` command, where *id* has the same meaning as for :meth:`stat`.
If the *file* parameter is supplied, then the body is stored in a file. If If the *file* parameter is supplied, then the body is stored in a file. If
*file* is a string, then the method will open a file object with that name, *file* is a string, then the method will open a file with that name, write
write to it then close it. If *file* is a file object, then it will start to it then close it. If *file* is a :term:`file object`, then it will start
calling :meth:`write` on it to store the lines of the body. Return as for calling :meth:`write` on it to store the lines of the body. Return as for
:meth:`head`. If *file* is supplied, then the returned *list* is an empty list. :meth:`head`. If *file* is supplied, then the returned *list* is an empty list.
...@@ -270,9 +270,9 @@ indicates an error, the method raises one of the above exceptions. ...@@ -270,9 +270,9 @@ indicates an error, the method raises one of the above exceptions.
text)``, where *id* is an article number (as a string) and *text* is the text of text)``, where *id* is an article number (as a string) and *text* is the text of
the requested header for that article. If the *file* parameter is supplied, then the requested header for that article. If the *file* parameter is supplied, then
the output of the ``XHDR`` command is stored in a file. If *file* is a string, the output of the ``XHDR`` command is stored in a file. If *file* is a string,
then the method will open a file object with that name, write to it then close then the method will open a file with that name, write to it then close it.
it. If *file* is a file object, then it will start calling :meth:`write` on it If *file* is a :term:`file object`, then it will start calling :meth:`write` on
to store the lines of the command output. If *file* is supplied, then the it to store the lines of the command output. If *file* is supplied, then the
returned *list* is an empty list. returned *list* is an empty list.
...@@ -303,8 +303,8 @@ indicates an error, the method raises one of the above exceptions. ...@@ -303,8 +303,8 @@ indicates an error, the method raises one of the above exceptions.
Process an ``XGTITLE`` command, returning a pair ``(response, list)``, where Process an ``XGTITLE`` command, returning a pair ``(response, list)``, where
*list* is a list of tuples containing ``(name, title)``. If the *file* parameter *list* is a list of tuples containing ``(name, title)``. If the *file* parameter
is supplied, then the output of the ``XGTITLE`` command is stored in a file. is supplied, then the output of the ``XGTITLE`` command is stored in a file.
If *file* is a string, then the method will open a file object with that name, If *file* is a string, then the method will open a file with that name, write
write to it then close it. If *file* is a file object, then it will start to it then close it. If *file* is a :term:`file object`, then it will start
calling :meth:`write` on it to store the lines of the command output. If *file* calling :meth:`write` on it to store the lines of the command output. If *file*
is supplied, then the returned *list* is an empty list. This is an optional NNTP is supplied, then the returned *list* is an empty list. This is an optional NNTP
extension, and may not be supported by all servers. extension, and may not be supported by all servers.
...@@ -320,8 +320,8 @@ indicates an error, the method raises one of the above exceptions. ...@@ -320,8 +320,8 @@ indicates an error, the method raises one of the above exceptions.
tuple is of the form ``(article number, subject, poster, date, id, references, tuple is of the form ``(article number, subject, poster, date, id, references,
size, lines)``. If the *file* parameter is supplied, then the output of the size, lines)``. If the *file* parameter is supplied, then the output of the
``XOVER`` command is stored in a file. If *file* is a string, then the method ``XOVER`` command is stored in a file. If *file* is a string, then the method
will open a file object with that name, write to it then close it. If *file* will open a file with that name, write to it then close it. If *file* is a
is a file object, then it will start calling :meth:`write` on it to store the :term:`file object`, then it will start calling :meth:`write` on it to store the
lines of the command output. If *file* is supplied, then the returned *list* is lines of the command output. If *file* is supplied, then the returned *list* is
an empty list. This is an optional NNTP extension, and may not be supported by an empty list. This is an optional NNTP extension, and may not be supported by
all servers. all servers.
......
...@@ -526,7 +526,7 @@ process and user. ...@@ -526,7 +526,7 @@ process and user.
File Object Creation File Object Creation
-------------------- --------------------
These functions create new file objects. (See also :func:`open`.) These functions create new :term:`file objects <file object>`. (See also :func:`open`.)
.. function:: fdopen(fd[, mode[, bufsize]]) .. function:: fdopen(fd[, mode[, bufsize]])
...@@ -562,7 +562,7 @@ is slightly deceptive; on Unix platforms, sockets and pipes are also referenced ...@@ -562,7 +562,7 @@ is slightly deceptive; on Unix platforms, sockets and pipes are also referenced
by file descriptors. by file descriptors.
The :meth:`~file.fileno` method can be used to obtain the file descriptor The :meth:`~file.fileno` method can be used to obtain the file descriptor
associated with a file object when required. Note that using the file associated with a :term:`file object` when required. Note that using the file
descriptor directly will bypass the file object methods, ignoring aspects such descriptor directly will bypass the file object methods, ignoring aspects such
as internal buffering of data. as internal buffering of data.
...@@ -679,9 +679,9 @@ as internal buffering of data. ...@@ -679,9 +679,9 @@ as internal buffering of data.
Force write of file with filedescriptor *fd* to disk. On Unix, this calls the Force write of file with filedescriptor *fd* to disk. On Unix, this calls the
native :cfunc:`fsync` function; on Windows, the MS :cfunc:`_commit` function. native :cfunc:`fsync` function; on Windows, the MS :cfunc:`_commit` function.
If you're starting with a Python file object *f*, first do ``f.flush()``, and If you're starting with a buffered Python :term:`file object` *f*, first do
then do ``os.fsync(f.fileno())``, to ensure that all internal buffers associated ``f.flush()``, and then do ``os.fsync(f.fileno())``, to ensure that all internal
with *f* are written to disk. buffers associated with *f* are written to disk.
Availability: Unix, and Windows. Availability: Unix, and Windows.
...@@ -738,9 +738,9 @@ as internal buffering of data. ...@@ -738,9 +738,9 @@ as internal buffering of data.
.. note:: .. note::
This function is intended for low-level I/O. For normal usage, use the This function is intended for low-level I/O. For normal usage, use the
built-in function :func:`open`, which returns a "file object" with built-in function :func:`open`, which returns a :term:`file object` with
:meth:`~file.read` and :meth:`~file.write` methods (and many more). To :meth:`~file.read` and :meth:`~file.write` methods (and many more). To
wrap a file descriptor in a "file object", use :func:`fdopen`. wrap a file descriptor in a file object, use :func:`fdopen`.
.. function:: openpty() .. function:: openpty()
......
...@@ -143,8 +143,8 @@ process more convenient: ...@@ -143,8 +143,8 @@ process more convenient:
.. function:: dump(obj, file, protocol=None, \*, fix_imports=True) .. function:: dump(obj, file, protocol=None, \*, fix_imports=True)
Write a pickled representation of *obj* to the open file object *file*. This Write a pickled representation of *obj* to the open :term:`file object` *file*.
is equivalent to ``Pickler(file, protocol).dump(obj)``. This is equivalent to ``Pickler(file, protocol).dump(obj)``.
The optional *protocol* argument tells the pickler to use the given protocol; The optional *protocol* argument tells the pickler to use the given protocol;
supported protocols are 0, 1, 2, 3. The default protocol is 3; a supported protocols are 0, 1, 2, 3. The default protocol is 3; a
...@@ -155,8 +155,9 @@ process more convenient: ...@@ -155,8 +155,9 @@ process more convenient:
Python needed to read the pickle produced. Python needed to read the pickle produced.
The *file* argument must have a write() method that accepts a single bytes The *file* argument must have a write() method that accepts a single bytes
argument. It can thus be a file object opened for binary writing, a argument. It can thus be an on-disk file opened for binary writing, a
io.BytesIO instance, or any other custom object that meets this interface. :class:`io.BytesIO` instance, or any other custom object that meets this
interface.
If *fix_imports* is True and *protocol* is less than 3, pickle will try to If *fix_imports* is True and *protocol* is less than 3, pickle will try to
map the new Python 3.x names to the old module names used in Python 2.x, map the new Python 3.x names to the old module names used in Python 2.x,
...@@ -181,8 +182,8 @@ process more convenient: ...@@ -181,8 +182,8 @@ process more convenient:
.. function:: load(file, \*, fix_imports=True, encoding="ASCII", errors="strict") .. function:: load(file, \*, fix_imports=True, encoding="ASCII", errors="strict")
Read a pickled object representation from the open file object *file* and Read a pickled object representation from the open :term:`file object` *file*
return the reconstituted object hierarchy specified therein. This is and return the reconstituted object hierarchy specified therein. This is
equivalent to ``Unpickler(file).load()``. equivalent to ``Unpickler(file).load()``.
The protocol version of the pickle is detected automatically, so no protocol The protocol version of the pickle is detected automatically, so no protocol
...@@ -191,9 +192,9 @@ process more convenient: ...@@ -191,9 +192,9 @@ process more convenient:
The argument *file* must have two methods, a read() method that takes an The argument *file* must have two methods, a read() method that takes an
integer argument, and a readline() method that requires no arguments. Both integer argument, and a readline() method that requires no arguments. Both
methods should return bytes. Thus *file* can be a binary file object opened methods should return bytes. Thus *file* can be an on-disk file opened
for reading, a BytesIO object, or any other custom object that meets this for binary reading, a :class:`io.BytesIO` object, or any other custom object
interface. that meets this interface.
Optional keyword arguments are *fix_imports*, *encoding* and *errors*, Optional keyword arguments are *fix_imports*, *encoding* and *errors*,
which are used to control compatiblity support for pickle stream generated which are used to control compatiblity support for pickle stream generated
...@@ -260,8 +261,8 @@ The :mod:`pickle` module exports two classes, :class:`Pickler` and ...@@ -260,8 +261,8 @@ The :mod:`pickle` module exports two classes, :class:`Pickler` and
Python needed to read the pickle produced. Python needed to read the pickle produced.
The *file* argument must have a write() method that accepts a single bytes The *file* argument must have a write() method that accepts a single bytes
argument. It can thus be a file object opened for binary writing, a argument. It can thus be an on-disk file opened for binary writing, a
io.BytesIO instance, or any other custom object that meets this interface. :class:`io.BytesIO` instance, or any other custom object that meets this interface.
If *fix_imports* is True and *protocol* is less than 3, pickle will try to If *fix_imports* is True and *protocol* is less than 3, pickle will try to
map the new Python 3.x names to the old module names used in Python 2.x, map the new Python 3.x names to the old module names used in Python 2.x,
...@@ -304,9 +305,9 @@ The :mod:`pickle` module exports two classes, :class:`Pickler` and ...@@ -304,9 +305,9 @@ The :mod:`pickle` module exports two classes, :class:`Pickler` and
The argument *file* must have two methods, a read() method that takes an The argument *file* must have two methods, a read() method that takes an
integer argument, and a readline() method that requires no arguments. Both integer argument, and a readline() method that requires no arguments. Both
methods should return bytes. Thus *file* can be a binary file object opened methods should return bytes. Thus *file* can be an on-disk file object opened
for reading, a BytesIO object, or any other custom object that meets this for binary reading, a :class:`io.BytesIO` object, or any other custom object
interface. that meets this interface.
Optional keyword arguments are *fix_imports*, *encoding* and *errors*, Optional keyword arguments are *fix_imports*, *encoding* and *errors*,
which are used to control compatiblity support for pickle stream generated which are used to control compatiblity support for pickle stream generated
......
...@@ -21,25 +21,24 @@ sending a graphics file. ...@@ -21,25 +21,24 @@ sending a graphics file.
.. function:: decode(input, output, header=False) .. function:: decode(input, output, header=False)
Decode the contents of the *input* file and write the resulting decoded binary Decode the contents of the *input* file and write the resulting decoded binary
data to the *output* file. *input* and *output* must either be file objects or data to the *output* file. *input* and *output* must be :term:`file objects
objects that mimic the file object interface. *input* will be read until <file object>`. *input* will be read until ``input.readline()`` returns an
``input.readline()`` returns an empty string. If the optional argument *header* empty string. If the optional argument *header* is present and true, underscore
is present and true, underscore will be decoded as space. This is used to decode will be decoded as space. This is used to decode "Q"-encoded headers as
"Q"-encoded headers as described in :rfc:`1522`: "MIME (Multipurpose Internet described in :rfc:`1522`: "MIME (Multipurpose Internet Mail Extensions)
Mail Extensions) Part Two: Message Header Extensions for Non-ASCII Text". Part Two: Message Header Extensions for Non-ASCII Text".
.. function:: encode(input, output, quotetabs, header=False) .. function:: encode(input, output, quotetabs, header=False)
Encode the contents of the *input* file and write the resulting quoted-printable Encode the contents of the *input* file and write the resulting quoted-printable
data to the *output* file. *input* and *output* must either be file objects or data to the *output* file. *input* and *output* must be :term:`file objects
objects that mimic the file object interface. *input* will be read until <file object>`. *input* will be read until ``input.readline()`` returns an
``input.readline()`` returns an empty string. *quotetabs* is a flag which empty string. *quotetabs* is a flag which controls whether to encode embedded
controls whether to encode embedded spaces and tabs; when true it encodes such spaces and tabs; when true it encodes such embedded whitespace, and when
embedded whitespace, and when false it leaves them unencoded. Note that spaces false it leaves them unencoded. Note that spaces and tabs appearing at the
and tabs appearing at the end of lines are always encoded, as per end of lines are always encoded, as per :rfc:`1521`. *header* is a flag
:rfc:`1521`. *header* is a flag which controls if spaces are encoded as which controls if spaces are encoded as underscores as per :rfc:`1522`.
underscores as per :rfc:`1522`.
.. function:: decodestring(s, header=False) .. function:: decodestring(s, header=False)
......
...@@ -78,11 +78,12 @@ The module defines the following: ...@@ -78,11 +78,12 @@ The module defines the following:
single: socket() (in module socket) single: socket() (in module socket)
single: popen() (in module os) single: popen() (in module os)
Among the acceptable object types in the sequences are Python file objects (e.g. Among the acceptable object types in the sequences are Python :term:`file
``sys.stdin``, or objects returned by :func:`open` or :func:`os.popen`), socket objects <file object>` (e.g. ``sys.stdin``, or objects returned by
objects returned by :func:`socket.socket`. You may also define a :dfn:`wrapper` :func:`open` or :func:`os.popen`), socket objects returned by
class yourself, as long as it has an appropriate :meth:`fileno` method (that :func:`socket.socket`. You may also define a :dfn:`wrapper` class yourself,
really returns a file descriptor, not just a random integer). as long as it has an appropriate :meth:`fileno` method (that really returns
a file descriptor, not just a random integer).
.. note:: .. note::
......
...@@ -2441,9 +2441,9 @@ to be provided for a context manager object to define a runtime context: ...@@ -2441,9 +2441,9 @@ to be provided for a context manager object to define a runtime context:
the identifier in the :keyword:`as` clause of :keyword:`with` statements using the identifier in the :keyword:`as` clause of :keyword:`with` statements using
this context manager. this context manager.
An example of a context manager that returns itself is a file object. File An example of a context manager that returns itself is a :term:`file object`.
objects return themselves from __enter__() to allow :func:`open` to be used as File objects return themselves from __enter__() to allow :func:`open` to be
the context expression in a :keyword:`with` statement. used as the context expression in a :keyword:`with` statement.
An example of a context manager that returns a related object is the one An example of a context manager that returns a related object is the one
returned by :func:`decimal.localcontext`. These managers set the active returned by :func:`decimal.localcontext`. These managers set the active
......
...@@ -108,9 +108,9 @@ This module defines one class called :class:`Popen`: ...@@ -108,9 +108,9 @@ This module defines one class called :class:`Popen`:
*stdin*, *stdout* and *stderr* specify the executed programs' standard input, *stdin*, *stdout* and *stderr* specify the executed programs' standard input,
standard output and standard error file handles, respectively. Valid values standard output and standard error file handles, respectively. Valid values
are :data:`PIPE`, an existing file descriptor (a positive integer), an are :data:`PIPE`, an existing file descriptor (a positive integer), an
existing file object, and ``None``. :data:`PIPE` indicates that a new pipe existing :term:`file object`, and ``None``. :data:`PIPE` indicates that a
to the child should be created. With ``None``, no redirection will occur; new pipe to the child should be created. With ``None``, no redirection will
the child's file handles will be inherited from the parent. Additionally, occur; the child's file handles will be inherited from the parent. Additionally,
*stderr* can be :data:`STDOUT`, which indicates that the stderr data from the *stderr* can be :data:`STDOUT`, which indicates that the stderr data from the
applications should be captured into the same file handle as for stdout. applications should be captured into the same file handle as for stdout.
...@@ -409,20 +409,20 @@ The following attributes are also available: ...@@ -409,20 +409,20 @@ The following attributes are also available:
.. attribute:: Popen.stdin .. attribute:: Popen.stdin
If the *stdin* argument was :data:`PIPE`, this attribute is a file object If the *stdin* argument was :data:`PIPE`, this attribute is a :term:`file
that provides input to the child process. Otherwise, it is ``None``. object` that provides input to the child process. Otherwise, it is ``None``.
.. attribute:: Popen.stdout .. attribute:: Popen.stdout
If the *stdout* argument was :data:`PIPE`, this attribute is a file object If the *stdout* argument was :data:`PIPE`, this attribute is a :term:`file
that provides output from the child process. Otherwise, it is ``None``. object` that provides output from the child process. Otherwise, it is ``None``.
.. attribute:: Popen.stderr .. attribute:: Popen.stderr
If the *stderr* argument was :data:`PIPE`, this attribute is a file object If the *stderr* argument was :data:`PIPE`, this attribute is a :term:`file
that provides error output from the child process. Otherwise, it is object` that provides error output from the child process. Otherwise, it is
``None``. ``None``.
......
...@@ -853,10 +853,10 @@ always available. ...@@ -853,10 +853,10 @@ always available.
stdout stdout
stderr stderr
File objects corresponding to the interpreter's standard input, output and error :term:`File objects <file object>` corresponding to the interpreter's standard
streams. ``stdin`` is used for all interpreter input except for scripts but input, output and error streams. ``stdin`` is used for all interpreter input
including calls to :func:`input`. ``stdout`` is used for except for scripts but including calls to :func:`input`. ``stdout`` is used
the output of :func:`print` and :term:`expression` statements and for the for the output of :func:`print` and :term:`expression` statements and for the
prompts of :func:`input`. The interpreter's own prompts prompts of :func:`input`. The interpreter's own prompts
and (almost all of) its error messages go to ``stderr``. ``stdout`` and and (almost all of) its error messages go to ``stderr``. ``stdout`` and
``stderr`` needn't be built-in file objects: any object is acceptable as long ``stderr`` needn't be built-in file objects: any object is acceptable as long
......
...@@ -66,8 +66,8 @@ Some facts and figures: ...@@ -66,8 +66,8 @@ Some facts and figures:
*mode* ``'r'`` to avoid this. If a compression method is not supported, *mode* ``'r'`` to avoid this. If a compression method is not supported,
:exc:`CompressionError` is raised. :exc:`CompressionError` is raised.
If *fileobj* is specified, it is used as an alternative to a file object opened If *fileobj* is specified, it is used as an alternative to a :term:`file object`
for *name*. It is supposed to be at position 0. opened in binary mode for *name*. It is supposed to be at position 0.
For special purposes, there is a second format for *mode*: For special purposes, there is a second format for *mode*:
``'filemode|[compression]'``. :func:`tarfile.open` will return a :class:`TarFile` ``'filemode|[compression]'``. :func:`tarfile.open` will return a :class:`TarFile`
...@@ -75,7 +75,7 @@ Some facts and figures: ...@@ -75,7 +75,7 @@ Some facts and figures:
be done on the file. If given, *fileobj* may be any object that has a be done on the file. If given, *fileobj* may be any object that has a
:meth:`read` or :meth:`write` method (depending on the *mode*). *bufsize* :meth:`read` or :meth:`write` method (depending on the *mode*). *bufsize*
specifies the blocksize and defaults to ``20 * 512`` bytes. Use this variant specifies the blocksize and defaults to ``20 * 512`` bytes. Use this variant
in combination with e.g. ``sys.stdin``, a socket file object or a tape in combination with e.g. ``sys.stdin``, a socket :term:`file object` or a tape
device. However, such a :class:`TarFile` object is limited in that it does device. However, such a :class:`TarFile` object is limited in that it does
not allow to be accessed randomly, see :ref:`tar-examples`. The currently not allow to be accessed randomly, see :ref:`tar-examples`. The currently
possible modes: possible modes:
...@@ -355,9 +355,9 @@ be finalized; only the internally used file object will be closed. See the ...@@ -355,9 +355,9 @@ be finalized; only the internally used file object will be closed. See the
.. method:: TarFile.extractfile(member) .. method:: TarFile.extractfile(member)
Extract a member from the archive as a file object. *member* may be a filename Extract a member from the archive as a file object. *member* may be a filename
or a :class:`TarInfo` object. If *member* is a regular file, a file-like object or a :class:`TarInfo` object. If *member* is a regular file, a :term:`file-like
is returned. If *member* is a link, a file-like object is constructed from the object` is returned. If *member* is a link, a file-like object is constructed from
link's target. If *member* is none of the above, :const:`None` is returned. the link's target. If *member* is none of the above, :const:`None` is returned.
.. note:: .. note::
...@@ -402,9 +402,9 @@ be finalized; only the internally used file object will be closed. See the ...@@ -402,9 +402,9 @@ be finalized; only the internally used file object will be closed. See the
.. method:: TarFile.gettarinfo(name=None, arcname=None, fileobj=None) .. method:: TarFile.gettarinfo(name=None, arcname=None, fileobj=None)
Create a :class:`TarInfo` object for either the file *name* or the file object Create a :class:`TarInfo` object for either the file *name* or the :term:`file
*fileobj* (using :func:`os.fstat` on its file descriptor). You can modify some object` *fileobj* (using :func:`os.fstat` on its file descriptor). You can modify
of the :class:`TarInfo`'s attributes before you add it using :meth:`addfile`. some of the :class:`TarInfo`'s attributes before you add it using :meth:`addfile`.
If given, *arcname* specifies an alternative name for the file in the archive. If given, *arcname* specifies an alternative name for the file in the archive.
......
...@@ -29,7 +29,7 @@ The module defines the following user-callable functions: ...@@ -29,7 +29,7 @@ The module defines the following user-callable functions:
.. function:: TemporaryFile(mode='w+b', buffering=None, encoding=None, newline=None, suffix='', prefix='tmp', dir=None) .. function:: TemporaryFile(mode='w+b', buffering=None, encoding=None, newline=None, suffix='', prefix='tmp', dir=None)
Return a file-like object that can be used as a temporary storage area. Return a :term:`file-like object` that can be used as a temporary storage area.
The file is created using :func:`mkstemp`. It will be destroyed as soon The file is created using :func:`mkstemp`. It will be destroyed as soon
as it is closed (including an implicit close when the object is garbage as it is closed (including an implicit close when the object is garbage
collected). Under Unix, the directory entry for the file is removed collected). Under Unix, the directory entry for the file is removed
......
...@@ -17,7 +17,7 @@ I/O control (and then only if configured at installation time). ...@@ -17,7 +17,7 @@ I/O control (and then only if configured at installation time).
All functions in this module take a file descriptor *fd* as their first All functions in this module take a file descriptor *fd* as their first
argument. This can be an integer file descriptor, such as returned by argument. This can be an integer file descriptor, such as returned by
``sys.stdin.fileno()``, or a file object, such as ``sys.stdin`` itself. ``sys.stdin.fileno()``, or a :term:`file object`, such as ``sys.stdin`` itself.
This module also defines all the constants needed to work with the functions This module also defines all the constants needed to work with the functions
provided here; these have the same name as their counterparts in C. Please provided here; these have the same name as their counterparts in C. Please
......
...@@ -58,8 +58,9 @@ is exposed by the :mod:`weakref` module for the benefit of advanced uses. ...@@ -58,8 +58,9 @@ is exposed by the :mod:`weakref` module for the benefit of advanced uses.
Not all objects can be weakly referenced; those objects which can include class Not all objects can be weakly referenced; those objects which can include class
instances, functions written in Python (but not in C), instance methods, sets, instances, functions written in Python (but not in C), instance methods, sets,
frozensets, file objects, :term:`generator`\s, type objects, sockets, arrays, frozensets, some :term:`file objects <file object>`, :term:`generator`\s, type
deques, regular expression pattern objects, and code objects. objects, sockets, arrays, deques, regular expression pattern objects, and code
objects.
.. versionchanged:: 3.2 .. versionchanged:: 3.2
Added support for thread.lock, threading.Lock, and code objects. Added support for thread.lock, threading.Lock, and code objects.
......
...@@ -92,8 +92,8 @@ Functions ...@@ -92,8 +92,8 @@ Functions
.. function:: iterparse(source, events=None, parser=None) .. function:: iterparse(source, events=None, parser=None)
Parses an XML section into an element tree incrementally, and reports what's Parses an XML section into an element tree incrementally, and reports what's
going on to the user. *source* is a filename or file object containing XML going on to the user. *source* is a filename or :term:`file object` containing
data. *events* is a list of events to report back. If omitted, only "end" XML data. *events* is a list of events to report back. If omitted, only "end"
events are reported. *parser* is an optional parser instance. If not events are reported. *parser* is an optional parser instance. If not
given, the standard :class:`XMLParser` parser is used. Returns an given, the standard :class:`XMLParser` parser is used. Returns an
:term:`iterator` providing ``(event, elem)`` pairs. :term:`iterator` providing ``(event, elem)`` pairs.
...@@ -455,15 +455,15 @@ ElementTree Objects ...@@ -455,15 +455,15 @@ ElementTree Objects
.. method:: parse(source, parser=None) .. method:: parse(source, parser=None)
Loads an external XML section into this element tree. *source* is a file Loads an external XML section into this element tree. *source* is a file
name or file object. *parser* is an optional parser instance. If not name or :term:`file object`. *parser* is an optional parser instance.
given, the standard XMLParser parser is used. Returns the section If not given, the standard XMLParser parser is used. Returns the section
root element. root element.
.. method:: write(file, encoding="us-ascii", xml_declaration=None, method="xml") .. method:: write(file, encoding="us-ascii", xml_declaration=None, method="xml")
Writes the element tree to a file, as XML. *file* is a file name, or a Writes the element tree to a file, as XML. *file* is a file name, or a
file object opened for writing. *encoding* [1]_ is the output encoding :term:`file object` opened for writing. *encoding* [1]_ is the output encoding
(default is US-ASCII). Use ``encoding="unicode"`` to write a Unicode string. (default is US-ASCII). Use ``encoding="unicode"`` to write a Unicode string.
*xml_declaration* controls if an XML declaration *xml_declaration* controls if an XML declaration
should be added to the file. Use False for never, True for always, None should be added to the file. Use False for never, True for always, None
......
...@@ -232,8 +232,8 @@ Reading and Writing Files ...@@ -232,8 +232,8 @@ Reading and Writing Files
builtin: open builtin: open
object: file object: file
:func:`open` returns a file object, and is most commonly used with two :func:`open` returns a :term:`file object`, and is most commonly used with
arguments: ``open(filename, mode)``. two arguments: ``open(filename, mode)``.
:: ::
......
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