This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author JTMoon79
Recipients JTMoon79, docs@python
Date 2011-01-19.00:12:25
SpamBayes Score 1.3785639e-12
Marked as misclassified No
Message-id <1295395949.96.0.0409847573272.issue10942@psf.upfronthosting.co.za>
In-reply-to
Content
method xml.etree.ElementTree.tostring from module returns type bytes.
The documentation reads
"""Returns an encoded string containing the XML data."""
(from http://docs.python.org/py3k/library/xml.etree.elementtree.html#xml.etree.ElementTree.tostring as of 2011-01-18)

=======================================================
Here is a test program:
-------------------------------------------------------
#!/usr/bin/python
# created for python 3.1

import sys
print(sys.version) # for help verifying version tested
from xml.etree import ElementTree

sampleinput = """<?xml version="1.0"?><Hello></Hello>"""
xmlobj = ElementTree.fromstring(sampleinput)
type(xmlobj)
xmlstr = ElementTree.tostring(xmlobj,'utf-8')
print("xmlstr value is '", xmlstr, "'", sep="")
print("xmlstr type is '", type(xmlstr), "'", sep="")
-------------------------------------------------------
test program output:
-------------------------------------------------------
3.1.3 (r313:86834, Nov 27 2010, 18:30:53) [MSC v.1500 32 bit (Intel)]
xmlstr value is 'b'<Hello />''
xmlstr type is '<class 'bytes'>'
=======================================================

This cheap "fix" for this bug may be simply be a change in documentation.
However, a method called "tostring" really should return something nearer to the built-in str.
History
Date User Action Args
2011-01-19 00:12:30JTMoon79setrecipients: + JTMoon79, docs@python
2011-01-19 00:12:29JTMoon79setmessageid: <1295395949.96.0.0409847573272.issue10942@psf.upfronthosting.co.za>
2011-01-19 00:12:25JTMoon79linkissue10942 messages
2011-01-19 00:12:25JTMoon79create