【发布时间】:2014-12-10 10:04:41
【问题描述】:
我正在使用以下方法解析 xml 文件:
lxml.etree.parse(xmlFile)
我提取了一些包含单个反斜杠的节点属性 并将它们保存到字典中
然后我使用以下命令将字典写入文件:
f = open(myFile, 'w')
for k, v in sorted(dic.items()):
f.write(str((k,v)))
f.write('\n')
f.flush()
f.close()
知道问题是如果我在解析后将树写入文件使用:
tree.write('output4.xml')
树与原始文件完全相同,但是 保存到 myFile 的字典有 \\ 而不是每个 \ 那么为什么 python 在它找到的地方添加 \。
示例: 这是原始属性:
"\displaystyle\mathbb{Z}_{n}\longrightarrow\mathbb{Z}"
在字典文件中变成:
'\\\displaystyle\\\mathbb{Z}_{n}\\\longrightarrow\\\mathbb{Z}'
【问题讨论】:
-
它只是代表......
标签: python python-3.x dictionary