dump() – Dump python object to file.

A simple xml parse and build lib.

lazyxml.dump(obj, fp, **kw)

Dump python object to file.

>>> import lazyxml
>>> data = {'demo': {'foo': 1, 'bar': 2}}
>>> lazyxml.dump(data, 'dump.xml')
>>> with open('dump-fp.xml', 'w') as fp:
>>>     lazyxml.dump(data, fp)
>>> from cStringIO import StringIO
>>> data = {'demo': {'foo': 1, 'bar': 2}}
>>> buffer = StringIO()
>>> lazyxml.dump(data, buffer)
>>> buffer.getvalue()
<?xml version="1.0" encoding="utf-8"?><demo><foo><![CDATA[1]]></foo><bar><![CDATA[2]]></bar></demo>
>>> buffer.close()

Note

kw argument have the same meaning as in dumps()

Parameters:
  • obj – data for dump to xml.
  • fp – a filename or a file or file-like object that support .write() to write the xml content

Changed in version 1.2: The fp is a filename of string. It can now be a file or file-like object that support .write() to write the xml content.