在python2.7中这样调用代码

open('file/name.txt','r',encoding= 'utf-8').read()

会出现

TypeError: 'encoding' is an invalid keyword argument for this function

这样的错误

需要将代码修改为

import io
io.open('file/name.txt','r',encoding= 'utf-8').read()

 

相关文章:

  • 2022-12-23
  • 2021-09-26
  • 2021-12-02
  • 2021-11-19
  • 2021-07-14
  • 2021-06-16
  • 2021-11-27
  • 2021-06-28
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-16
  • 2022-01-31
  • 2022-12-23
  • 2021-09-10
相关资源
相似解决方案