Message90891
I have a function to replace the content of an ElementTree Element by
that of another one which works using Python 2 but not with Python 3.
I get an assertion error.
It was suggested on the Python list that the problem is that in Python 3
slice assignments are done with __setitem__ rather than __setslice__ but
ElementTree has not been adapted to that -- hence the title given to
this bug.
The function that I use to demonstrate this (with a workaround solution)
is as follows:
def replace_element(elem, replacement):
'''replace the content of an ElementTree Element by that of
another
one.
'''
elem.clear()
elem.text = replacement.text
elem.tail = replacement.tail
elem.tag = replacement.tag
elem.attrib = replacement.attrib
try:
elem[:] = replacement[:] # works with Python 2.5 but not 3.1
except AssertionError:
del elem[:]
for child in replacement:
elem.append(child)
I have included a small test file which demonstrate the behaviour. |
|
Date |
User |
Action |
Args |
2009-07-24 19:46:53 | aroberge | set | recipients:
+ aroberge |
2009-07-24 19:46:53 | aroberge | set | messageid: <1248464813.63.0.470228683416.issue6565@psf.upfronthosting.co.za> |
2009-07-24 19:46:51 | aroberge | link | issue6565 messages |
2009-07-24 19:46:51 | aroberge | create | |
|