【发布时间】:2015-10-03 14:28:04
【问题描述】:
#open file and rewrite (comma) to ,
with open('outputFile') as fo:
fo.write(line.replace("(comma)"," , "))
我正在尝试将文本 (comma) 替换为文件中的文字 ,。当我运行上述代码时,出现以下错误:io.UnsupportedOperation: not writable
任何关于如何在文件中重写文本的见解将不胜感激。
我使用了下面的代码,它仍然不会用,替换(comma)
#open file and rewrite (comma) to ,
with open('outputFile.txt', "a+") as fo:
fo.write(fo.replace('(comma)',','))
fo.close()
【问题讨论】:
标签: python