Case Closed?


#1



https://www.codecademy.com/courses/python-intermediate-en-OGNHh/1/5?curriculum_id=4f89dab3d788890003000096#


I keep getting the error message:
Traceback (most recent call last):
File "python", line 2, in
IOError: File not open for writing


I don't know what I am doing wrong here.


with open("text.txt", "r") as textfile:
    textfile.write("hello")
    if textfile.closed == False:
        textfile.close()
print textfile.closed


#2

here:

with open("text.txt", "r") as textfile:

you open the file in read only mode, then you try to write to the file:

textfile.write("hello")

that doesn't work


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.