I'm generating some HTML using ElementTree in a Python script. The relevant part looks like this:
separator = ET.SubElement(toc, 'span')
separator.set('class', 'separator')
separator.text = u" ⬩"
The problem is that the HTML entity
is being encoded in the resulting XML output as  
, which puts the literal text
on the rendered web page, instead of inserting a non-breaking space.
I'm working around it by escaping a non-breaking space into the Python string like this: u"\u00A0⬩"
. This puts a literal non-breaking space in my HTML instead of the entity. Ultimately, it works because it is faithfully rendered as a non-breaking space, but it makes the source code hard to read because a non-breaking space looks like a regular space.
How can I get ElementTree to insert an HTML entity into my source code?