I have the following line of code in a python script:
dep11 = ET.SubElement(dep1, "POVCode").text = "#declare lg_quality = LDXQual;
#if (lg_quality = 3)
#declare lg_quality = 4;
#end"
My question is in regards to the 

character. I want to see this character entity in the XML output, but the first ampersand keeps getting replaced with the &
character entity, which creates the nonsense character entity 

.
I am encoding the file as utf-8
.
import xml.etree.ElementTree as ET
...
with open("LGEO.xml", "wb") as f:
tree.write(f, "utf-8")
And I end up with:
<POVCode>#declare lg_quality = LDXQual;&#x0A;#if (lg_quality = 3)&#x0A;#declare lg_quality = 4;&#x0A;#end</POVCode>
Not sure what I'm doing wrong.
[edit]
I am trying to implement the solution found here that @mzjn pointed out.
How to output XML entity references
I have six lines of code:
dep11 = ET.SubElement(dep1, "POVCode")
dep21 = ET.SubElement(dep2, "POVCode")
dep11.text = "#declare lg_quality = LDXQual;&
#if (lg_quality = 3)&
#declare lg_quality = 4;&
#end"
dep21.text = "#declare lg_studs = LDXStuds;&
"
ET.tostring(dep11).replace('&&', '&')
ET.tostring(dep21).replace('&&', '&')
I get no error, but the result is not any different than before when I write
the tree.
Again I am stuck.