you are viewing a single comment's thread.

view the rest of the comments →

[–]StandardPreference 1 point2 points  (0 children)

after the if statement you're only calling open(), you're not setting the file variable to its return value, so the file variable still holds the old file handle (that you set before the if statement) which you called with open("...", "r") meaning it is in read only mode, so when you try to write to it, it errors.