当前位置: 动力学知识库 > 问答 > 编程问答 >

Why would you open an xml file in binary mode for editing in Python?

问题描述:

According to Pydocs,

fp = file('blah.xml', 'w+b')

or

fp = file('blah.xml', 'wb')

means open the file in write and binary mode. This is an xml file, however, so why do these two chaps

http://www.pixelmender.com/2010/10/12/scraping-data-using-scrapy-framework/

and

http://doc.scrapy.org/topics/exporters.html#scrapy.contrib.exporter.XmlItemExporter

recommend doing so in their tutorial/docs pages about exporting Scrapy items? In other words, why would anyone open a new xml file in 'b' mode?

网友答案:

It just doesn't make sense with plain XML files. On Unix there is no difference between binary and non-binary. On Windows written '\n' get translated to '\r\n' if you write non-binary.

But it will make a difference if you embed binary BLOBs, but I don't see those on the sites you mentioned.

分享给朋友:
您可能感兴趣的文章:
随机阅读: