这里要读一个xml文件,并把数据写入csv。
python代码
python 3.8
def read_xml3():
doc = etree.parse("D:/tmp/bbc_text/bbc-text.xml")
root=doc.getroot()
news_items =[]
with open("D:/tmp/bbc_text/bbc_text_python.csv", "w", encoding="utf-8") as f:
f.write("category,text\n")
for news_item_xml in root.getchildren():
f.write(news_item_xml.attrib['category'])
f.write(",")
f.write(news_item_xml.text.replace('"','""'))
f.write("\n")
f.flush()
f.close()
C#代码
public class BbcNewsItem
{
public string Category {
get; set; }
public string Text {
get; set; }
}
public static

本文通过读取XML文件并写入CSV的数据操作对比了Python、C#(.NET Core和.NET Framework)以及C++的运行效率。C++表现最快,运行时间为34.8ms,Python在预期之外达到3.8ms,而.NET Core的235.8ms比Python慢两倍,但当切换到.NET Framework时,时间减半至57.6ms。尽管Python运行速度快于预期,但由于类型不安全和编程体验问题,作者认为它不适合用于应用程序开发。
最低0.47元/天 解锁文章
9595





