[Lxml-checkins] r43440 - lxml/trunk/doc
scoder at codespeak.net
scoder at codespeak.net
Wed May 16 22:49:36 CEST 2007
Author: scoder
Date: Wed May 16 22:49:36 2007
New Revision: 43440
Modified:
lxml/trunk/doc/tutorial.txt
Log:
paragraph on deep copying elements
Modified: lxml/trunk/doc/tutorial.txt
==============================================================================
--- lxml/trunk/doc/tutorial.txt (original)
+++ lxml/trunk/doc/tutorial.txt Wed May 16 22:49:36 2007
@@ -145,6 +145,20 @@
where elements can sit in multiple positions of any number of trees. In
lxml.etree, elements can only sit in one position of one tree at a time.
+If you want to *copy* an element to a different position, consider creating a
+independent *deep copy* using the ``copy`` module from Python's standard
+library::
+
+ >>> from copy import deepcopy
+
+ >>> element = etree.Element("neu")
+ >>> element.append( deepcopy(root[1]) )
+
+ >>> print element[0].tag
+ child1
+ >>> print [ c.tag for c in root ]
+ ['child3', 'child1', 'child2']
+
To retrieve a 'real' Python list of all children (or a *shallow copy* of the
element children list), you can call the ``getchildren()`` method::
More information about the lxml-checkins
mailing list