打开代码如下:
f=open("123.txt","rt","encode=utf-8")
for i in f:
i=i.split(",")
print(i)
报错如下:
=RESTART: C:\Users\Zz\AppData\Local\Programs\Python\Python38-32\program\practise11.py
Traceback (most recent call last):
File "C:\Users\Zz\AppData\Local\Programs\Python\Python38-32\program\practise11.py", line 1, in <module>
f=open("123.txt","rt","encode=utf-8")
TypeError: an integer is required (got type str)
``
这是我想打开输出的文件
另外,为什么我的文件里有逗号的话,open就需要写“encode=utf-8”?
求大神解答
f=open("123.txt","rb+",encoding="utf-8")
你的文档有中文就要encoding
没有用
报错信息里指示 f=open("123.txt","rt","encode=utf-8") 里有 type error, 是参数类型错误,编码参数要加参数名称,另外这条语句还有其它错误:
正确写法: f=open("123.txt","rb",encoding="utf-8")