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

北城以北 提交于 2019-12-09 12:27:33

fo = open(“test.txt”, “r+”,encoding=“utf-8”)
print (“file name:”, fo.name)
line = fo.read(2)
print (“readline: %s” % (line))
fo.close()
上面代码提示错误python2.7.16 TypeError: ‘encoding’ is an invalid keyword argument for this function
修改为:
import io

fo = io.open(“test.txt”, “r+”,encoding=“utf-8”)
print (“test_roger\r\n”)
print (“file name:”, fo.name)
line = fo.read(2)
print (“readline: %s” % (line))
fo.close()
错误解决

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!