python3.0可以这样写
f = open('ufile.log', 'w', 'utf-8')
 
但在python2.7中open()没有编码参数,如上那样写会报错,可以使用如下模块
import codecs    #这个模块可以实现。
s = '中文;113456789876543234567'
f = codecs.open('ufile.log', 'w', 'utf-8')
f.write(s.decode('utf-8'))
f.close()
 

 

---------------------------------------------------------------------------------

关注微信公众号即可在手机上查阅,并可接收更多测试分享~

python2.7写入文件时指定编码为utf-8

相关文章:

  • 2021-11-30
  • 2021-12-08
  • 2021-09-16
  • 2022-12-23
  • 2022-01-07
  • 2021-08-16
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-03
  • 2021-10-15
  • 2021-05-24
  • 2022-12-23
相关资源
相似解决方案