Zzsf11
2020-03-22 15:32
采纳率: 100%
浏览 8.5k

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

求大神解答
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • 已采纳

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

    你的文档有中文就要encoding

    点赞 1 打赏 评论

相关推荐