PermissionError: [Errno 13] in python

500    Asked by Aalapprabhakaran in Python , Asked on Apr 6, 2021

Just starting to learn some python and I'm having an issue as stated below:

a_file = open('E:Python Win7-64-AMD 3.3Test', encoding='utf-8')

Traceback (most recent call last):

  File "", line 1, in

    a_file = open('E:Python Win7-64-AMD 3.3Test', encoding='utf-8')

PermissionError: [Errno 13] Permission denied: 'E:\Python Win7-64-AMD 3.3\Test

Seems to be a file permission error, if any one can shine some light it would be greatly appreciated.

NOTE: not sure how Python and Windows files work but I'm logged in to Windows as Admin and the folder has admin permissions.

I have tried changing .exe properties to run as Admin.


If you are facing permission error python then you can follow the below-mentioned code;

a_file = open('E:Python Win7-64-AMD 3.3Test', encoding='utf-8')
Then, you're trying to open a directory as a file, which may (and on most non UNIX file systems will) fail. Your other example though;
a_file = open('E:Python Win7-64-AMD 3.3Test.txt', encoding='utf-8')

It'll work well if you just have the permission on a.txt. You may want to use a raw (r-prefixed) string though, to make sure your path does not contain any escape characters like
that will be translated to special characters.

    a_file = open(r'E:Python Win7-64-AMD 3.3Test.txt', encoding='utf-8')


Your Answer

Interviews

Parent Categories