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

Reposted from: https://www.cnblogs.com/vercont/p/10210233.html

Call the code like this in python2.7

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

Will appear

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

such mistakes

The code needs to be modified to

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

Guess you like

Origin blog.csdn.net/auccy/article/details/131073646