如何使用python 3.4读取文本文档

时间:2015-11-24 20:03:16

标签: python python-3.x

我想打开一个文本文档。我收到错误TypeError: an integer is required (got type str) 这是我的代码

doc=open("bradley.txt","r","UTF-8")
doc.read(5)
print(doc.read(5))

1 个答案:

答案 0 :(得分:0)

打开

doc=open("bradley.txt","r",encoding="UTF-8")

docs:https://docs.python.org/3/library/io.html?highlight=open#io.open