-2

So this is my code snippet. I keep getting the error "io.UnsupportedOperation: not writable"

outputfile = open("output.txt")
for line in lines:
    outputfile.write(line)

outputfile.close()
0

1 Answer 1

1

By default, open() opens files for reading, not writing. To open a file for writing, you need to specify 'w' as the mode:

outputfile = open("output.txt", 'w')
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.