读取文件出现\ufeff情况解决

with open('test.txt', 'r') as f:
    content = f.read()
# 若读取的content中头部出现\ufeff
new_content = content.encode('utf-8').decode('utf-8-sig')

具体原因见:https://www.cnblogs.com/mjiang2017/p/8431977.html

你可能感兴趣的:(读取文件出现\ufeff情况解决)