Steve Barrett Steve Barrett - 5 days ago 6
Python Question

python loop io.UnsupportedOperation: not writable

I am getting the following error when trying to output to a text file:
io.UnsupportedOperation: not writable

Any help appreciated. thanks

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

Answer

Your problem is that you're writing to the wrong file.

You have opened f, so you should write to f, not to google_searches:

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