Extra characters in readlines and join python? How to remove “”? Byte Order Mark?

不羁岁月 提交于 2019-12-13 15:44:55

问题


The python code:

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()

The extra characters that show up even if the file is "blank" are 

When I open the file in Notepad++ and "show all symobls" I still get these BOM characters when the .txt file appears to be blank.

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

Is it as simple as lines.replace("","") ? Or is there something I am missing?

One Solution:

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

来源:https://stackoverflow.com/questions/20848761/extra-characters-in-readlines-and-join-python-how-to-remove-%c3%af-byte-order-m

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!