0 votes
1 view
in Python by (22.4k points)

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

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

Traceback (most recent call last):

  File "<pyshell#9>", line 1, in <module>

    a_file = open('E:\Python Win7-64-AMD 3.3\Test', 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.

2 Answers

0 votes
by (22.4k points)

If you are doing this;

a_file = open('E:\Python Win7-64-AMD 3.3\Test', 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.3\Test\a.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 \n that will be translated to special characters.

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

0 votes
by (40.3k points)

If you are doing this;

a_file = open('E:\Python Win7-64-AMD 3.3\Test', 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.3\Test\a.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 \n that will be translated to special characters.

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

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...