TypeError: 'encoding' is an invalid keyword argument for this function 解决Python 2.7

版权声明:版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/DarrenXf/article/details/82903961

在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()

猜你喜欢

转载自blog.csdn.net/DarrenXf/article/details/82903961