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()
错误解决
来源:CSDN
作者:roger107
链接:https://blog.csdn.net/hurg101/article/details/103455049