python删除xml文件上的注释
xml文件包含以下返回:python删除xml文件上的注释,python,python-3.x,xml,xml-parsing,elementtree,Python,Python 3.x,Xml,Xml Parsing,Elementtree,xml文件包含以下返回: <!-- This xml is designed for testing --> <returns> <obs>0.008053735</obs> <obs>0.004752907</obs> <obs>0.004682267</obs> <obs>0.003029358</obs> </returns>
<!-- This xml is designed for testing -->
<returns>
<obs>0.008053735</obs>
<obs>0.004752907</obs>
<obs>0.004682267</obs>
<obs>0.003029358</obs>
</returns>
我想删除XML的注释行。有人知道怎么做吗
谢谢,,
L那么您想修改文件吗?是的,我想修改xml文件的内容。看看这是否有帮助:您的预期输出是什么?
import xml.etree.ElementTree as ET
import numpy as np
r=[]
def LoadReturn():
try:
treexml = ET.parse('./sample_data/returns.xml')
root = treexml.getroot()
for ts in root:
r.append(ts.text)
except:
print("Failed to parse xml from response (%s)" % traceback.format_exc())
return r