Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f96cf91

Browse files
committed
Issue #9458: clarify the documentation of ElementTree.write with regards to the type of the stream expected for a given encoding
1 parent 00f402b commit f96cf91

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

Doc/library/xml.etree.elementtree.rst

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -650,15 +650,25 @@ ElementTree Objects
650650
section root element.
651651

652652

653-
.. method:: write(file, encoding="us-ascii", xml_declaration=None, method="xml")
653+
.. method:: write(file, encoding="us-ascii", xml_declaration=None, \
654+
method="xml")
654655

655656
Writes the element tree to a file, as XML. *file* is a file name, or a
656-
:term:`file object` opened for writing. *encoding* [1]_ is the output encoding
657-
(default is US-ASCII). Use ``encoding="unicode"`` to write a Unicode string.
658-
*xml_declaration* controls if an XML declaration
659-
should be added to the file. Use False for never, True for always, None
660-
for only if not US-ASCII or UTF-8 or Unicode (default is None). *method* is
661-
either ``"xml"``, ``"html"`` or ``"text"`` (default is ``"xml"``).
657+
:term:`file object` opened for writing. *encoding* [1]_ is the output
658+
encoding (default is US-ASCII).
659+
*xml_declaration* controls if an XML declaration should be added to the
660+
file. Use ``False`` for never, ``True`` for always, ``None``
661+
for only if not US-ASCII or UTF-8 or Unicode (default is ``None``).
662+
*method* is either ``"xml"``, ``"html"`` or ``"text"`` (default is
663+
``"xml"``).
664+
665+
The output is either a string (:class:`str`) or binary (:class:`bytes`).
666+
This is controlled by the *encoding* argument. If *encoding* is
667+
``"unicode"``, the output is a string; otherwise, it's binary. Note that
668+
this may conflict with the type of *file* if it's an open
669+
:term:`file object`; make sure you do not try to write a string to a
670+
binary stream and vice versa.
671+
662672

663673
This is the XML file that is going to be manipulated::
664674

0 commit comments

Comments
 (0)