New submission from Andre Roberge <andre.robe...@gmail.com>: 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. ---------- components: Library (Lib) files: test.py messages: 90891 nosy: aroberge severity: normal status: open title: improper use of __setitem__ in ElementTree for Python 3.1 type: behavior versions: Python 3.1 Added file: http://bugs.python.org/file14560/test.py _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue6565> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com