Zzsf11 2020-03-22 15:32 采纳率: 33.3%
浏览 11611
已采纳

python文件打开报错TypeError: an integer is required (got type str)求解

打开代码如下:

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”?

求大神解答
  • 写回答

3条回答 默认 最新

  • threenewbee 2020-03-22 21:23
    关注

    f=open("123.txt","rb+",encoding="utf-8")

    你的文档有中文就要encoding

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?