Python要将文件保存为utf-8带BOM格式如何操作,,s = u中文f = c


s = u'中文'f = codecs.open('ufile.log', 'w', "UTF-8")f.write(s)f.close()

Python中如何将文件保存为utf-8(带BOM)的格式,如果使用以上代码,则文件的格式为:utf-8无BOM

f = codecs.open('ufile.log', 'w', 'utf_8_sig')

参见: 7.8.6. encodings.utf_8_sig — UTF-8 codec with BOM signature

编橙之家文章,

评论关闭