There are different versions of ElementTree.
Some of them accept the xml_declaration
argument, some do not.
The one I happen to have does not. It emits the declaration if and only if encoding != 'utf-8'
. So, to get the declaration, I call write(filename, encoding='UTF-8')
.