首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Python IOError:未打开文件进行读取

Python IOError:未打开文件进行读取
EN

Stack Overflow用户
提问于 2012-11-09 22:04:28
回答 2查看 62.7K关注 0票数 23

当我尝试在Python中打开一个文件时,我得到一个错误。下面是我的代码:

代码语言:javascript
复制
>>> import os.path
>>> os.path.isfile('/path/to/file/t1.txt')
>>> True
>>> myfile = open('/path/to/file/t1.txt','w')
>>> myfile
>>> <open file '/path/to/file/t1.txt', mode 'w' at 0xb77a7338>
>>> myfile.readlines()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: File not open for reading

我也试过了:

代码语言:javascript
复制
for line in myfile:
    print(line)

我得到了同样的错误。有人知道为什么会发生这个错误吗?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13309548

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档