问题描述
刚开始学习一些 Python,我遇到了如下所述的问题:
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 "<pyshell#9>", line 1, in <module>
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.
注意:不确定 Python 和 Windows 文件如何工作,但我以管理员身份登录到 Windows,并且该文件夹具有管理员权限.
我已尝试将 .exe
属性更改为以管理员身份运行.
I have tried changing .exe
properties to run as Admin.
推荐答案
什么时候做;
a_file = open('E:Python Win7-64-AMD 3.3Test', encoding='utf-8')
...您正在尝试将 目录 作为文件打开,这可能(并且在大多数非 UNIX 文件系统上)会失败.
...you're trying to open a directory as a file, which may (and on most non UNIX file systems will) fail.
你的另一个例子;
a_file = open('E:Python Win7-64-AMD 3.3Testa.txt', encoding='utf-8')
如果您只有 a.txt
的权限,应该可以正常工作.您可能希望使用原始(r
-prefixed)字符串,以确保您的路径不包含任何转义字符,如
将被转换为特殊字符.
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
that will be translated to special characters.
a_file = open(r'E:Python Win7-64-AMD 3.3Testa.txt', encoding='utf-8')
这篇关于PermissionError:Python 中的 [Errno 13]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!