First time here? Check out the FAQ!

Ask Your Question
0

Error if an output file already exists (matplotlib)

asked 14 years ago

manifold gravatar image

updated 13 years ago

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?

Preview: (hide)

Comments

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

manifold gravatar imagemanifold ( 14 years ago )

1 Answer

Sort by » oldest newest most voted
1

answered 14 years ago

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?

Preview: (hide)
link

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: 14 years ago

Seen: 2,959 times

Last updated: Feb 19 '11