【发布时间】:2019-01-04 10:52:41
【问题描述】:
我现在正在学习 Python,并且正在尝试在 MacOS 上使用 PyCharm CE 学习文件处理。在尝试打开或创建新文件时,我收到类似这样的错误 -
io.UnsupportedOperation: not readable
我的代码如下所示:
import os
print (os.path.abspath(os.curdir))
fhand = open("file1.rtf", "w")
for line in fhand:
if line.startswith("from :") :
line = line.strip()
print(line)
如何打开文件并在其中写入内容?这段代码有什么问题?
【问题讨论】:
-
查看链接问题:与pycharm无关。问题是您将
"w"传递给open()使文件对象只写
标签: python macos file unsupportedoperation