Python中如何将文件保存为utf-8(带BOM)的格式
PHPz
PHPz 2017-04-17 13:59:29
0
1
700
s = u'中文'
f = codecs.open('ufile.log', 'w', "UTF-8")
f.write(s)
f.close()

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

PHPz
PHPz

学习是最好的投资!

répondre à tous(1)
Ty80
f = codecs.open('ufile.log', 'w', 'utf_8_sig')

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

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!