I am parsing xml file using:
lxml.etree.parse(xmlFile)
I extracted some node attributes which contain single backslash and save them into dictionary
Then I write the dictionary into a file using:
f = open(myFile, 'w')
for k, v in sorted(dic.items()):
f.write(str((k,v)))
f.write('\n')
f.flush()
f.close()
Know the problem is that after parsing if I write the tree into a file using:
tree.write('output4.xml')
the tree is exactly as the original file BUT the dictionary that saved into myFile has \\ instead of each \ So why python adding \ wherever it found one.
Example: this is the original attribute:
"\displaystyle\mathbb{Z}_{n}\longrightarrow\mathbb{Z}"
and in the dictionary file it becomes:
'\\\displaystyle\\\mathbb{Z}_{n}\\\longrightarrow\\\mathbb{Z}'