python循环io.UnsupportedOperation:不是writab

2024-06-16 10:19:49 发布

您现在位置:Python中文网/ 问答频道 /正文

尝试输出到文本文件时出现以下错误: io.UNSUPPOREDOPERATION:不可写

感谢任何帮助。谢谢

f = open("google-searches.txt", "w+")
for item in results:
    google_searches.write("%s\n" % item)

Tags: iniotxtfor错误googleopenitem
2条回答

你应该写信

f = open("google-searches.txt", "w+")
for item in results:
    f.write("%s\n" % item)

因为您打开的文件对象是f

你的问题是你写错了文件。

您已经打开了f,因此您应该将f写入,而不是google_searches

f = open("google-searches.txt", "w+")
for item in results:
    f.write("%s\n" % item)

相关问题 更多 >