Ask Your Question

Error if an output file already exists (matplotlib)

asked 2011-02-19 11:25:05 +0200

manifold gravatar image

updated 2011-06-16 15:27:03 +0200

Kelvin Li gravatar image

If I have a file already, and try to overwrite it, I get an error:

    file =, mode, buffering)
IOError: [Errno 13] Permission denied:

I use the matplotlib savefig function.

Full Error Output:

The error only occurs if I restart the worksheet. If I manually delete all the file(s), there is no problem. How can I fix it? An easy solution would be to delete the output files before I try to overwrite them, but how can I delete files?

edit retag flag offensive close merge delete


I found a quick and dirty way: import os os.remove(DATA+"CSVFullOutput.csv")

manifold gravatar imagemanifold ( 2011-02-19 13:09:58 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2011-02-19 14:52:40 +0200

benjaminfjones gravatar image

Telling the operating system to delete the files works. According to the python documentation of the builtin open method, the open mode w does the following:

'w' for only writing (an existing file with the same name will be erased)

Assuming that's what your mode is set to, I would expect this behavior, so I don't understand why you're getting the error. It's possible that the error is due to the permissions of the files you're trying to overwrite. Try deleting them manually, then use your code to create them again and inspect the permissions. Maybe your umask needs to be changed?

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2011-02-19 11:25:05 +0200

Seen: 2,783 times

Last updated: Feb 19 '11