readlines中的额外字符和加入python?如何删除“”?字节顺序标记?

时间:2013-12-30 22:40:37

标签: python join byte-order-mark readlines

python代码:

sku_specs = "./item_specs.txt"

def item_specs():

    g = open(sku_specs,"r")
    lines = g.readlines()
    lines = "<br />".join(lines)
    return lines

f = open("ouput.txt","a")
f.write("Some stuff"+item_specs()+"more stuff")
f.write("more stuff")
f.close()

即使文件为“空白”,显示的额外字符为

当我在Notepad ++中打开文件并“显示所有symobls”时,当.txt文件显示为空白时,我仍然会收到这些BOM字符。

相关:How do I remove  from the beginning of a file?

是否像lines.replace(“”,“”)一样简单?或者有什么我想念的东西?

一个解决方案:

    lines = lines.decode("utf-8-sig")
    lines = lines.encode('utf-8','ignore')

0 个答案:

没有答案