Reputation: 110412
I have an existing file I want to remove, and I get the following error when trying to remove it:
os.remove(input_path)
OSError: [Errno 13] Permission denied:
Is there any way to remove a file that already exists, other than doing:
subprocess.call(['rm', input_path])
Upvotes: 4
Views: 7238
Reputation: 64328
Since you're getting a "permission denied" error, it is clear there's a "mismatch" between the permissions of the file (or its parent directory), and those of the user running the python process.
The best practice, instead of looking for "shortcuts" in the form of sudo
, is to fix the permissions, either of the file being deleted, or the user running the python process.
Permissions are used for a reason. You're risking getting into troubles if you choose to void/bypass them by using tricks such as sudo
.
Upvotes: 3