Ask Your Question
0

Error if an output file already exists (matplotlib)

asked 2011-02-19 04:25:05 -0500

manifold gravatar image

updated 2011-06-16 08:27:03 -0500

Kelvin Li gravatar image

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

    file = __builtin__.open(filename, mode, buffering)
IOError: [Errno 13] Permission denied:

I use the matplotlib savefig function.

Full Error Output: http://rn0.ru/show/8AXiJGpriPqIQa8cdcGk/

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

Comments

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

manifold gravatar imagemanifold ( 2011-02-19 06:09:58 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2011-02-19 07:52:40 -0500

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

Stats

Asked: 2011-02-19 04:25:05 -0500

Seen: 1,128 times

Last updated: Feb 19 '11