Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python权限错误_Python_Permissions - Fatal编程技术网

python权限错误

python权限错误,python,permissions,Python,Permissions,我在Mac OS中有一个文件a.txt,每个人都有写perm: sh-3.2# ls -hal a.txt -rw-rw-rw- 1 root wheel 0B Dec 8 11:34 a.txt sh-3.2# pwd /var/root 但是在python中,它给了我一个错误: >>> fob=open("/var/root/a.txt","w") Traceback (most recent call last): File "<pyshel

我在Mac OS中有一个文件
a.txt
,每个人都有写perm:

sh-3.2# ls -hal a.txt 
-rw-rw-rw-  1 root  wheel     0B Dec  8 11:34 a.txt
sh-3.2# pwd
/var/root
但是在python中,它给了我一个错误:

>>> fob=open("/var/root/a.txt","w")

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    fob=open("/var/root/a.txt","w")
IOError: [Errno 13] Permission denied: '/var/root/a.txt'
fob=open(“/var/root/a.txt”,“w”) 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 fob=打开(“/var/root/a.txt”,“w”) IOError:[Errno 13]权限被拒绝:'/var/root/a.txt'
问题:为什么?

很可能您对文件所在的目录没有写权限。

我猜
/var/root
目录的权限对您运行的用户来说太严格了。

只是一个粗略的猜测:既然文件已经存在,是否有可能以“w+”模式打开或者“r+”而不是“w”允许您写入文件

我并没有可用的OSX计算机,很可能是目录权限的问题,但我会尝试更改模式,以防万一