Python | PermissionError: [Errno 13] Permission denied:


I am currently learning Python using Al Sweigart’s book. I have an issue with the open function when passing ‘w’ as an argument: it is supposed to create a file if the the filename I passed doesn’t exist but it doesn’t and instead it shows the error message in the image (this is an example from the book)

baconFile = open('bacon.txt', 'w')
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
baconFile = open('bacon.txt', 'w')
PermissionError: [Errno 13] Permission denied: 'bacon.txt'

Tha same error gets displayed when I use from the shelve open.

Thank you for any explanation/solution.

I tried openeing other files with ‘w’ as an argument and it works only if the file exists already but if I try to open a non-existing one, it doesn’t create it like it’s supposed to and it just displays the same error.

>Solution :

The file bacon.txt is owned by a different user account.

You are running the program as a user that does not have permission to overwrite it.

Leave a ReplyCancel reply