PermissionError: [Errno 13] in python

匿名 (未验证) 提交于 2019-12-03 01:57:01

问题:

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 "", line 1, in      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.

回答1:

When doing;

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

...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') 

should 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') 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!