python permission error
I have a file a.txt
in Mac OS, which has write perms to everybody:
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
however in python it gi开发者_运维问答ves me an error:
>>> 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'
question: why?
I'm going to guess that the permissions on the /var/root
directory are too strict for the user you are running as.
It's likely that you don't have write permission on the directory that the file is in.
Just a wild guess: since the file already exists there, is it possible that opening with mode "w+" or "r+" instead of "w" allows you to write to the file?
I don't have an OS X computer available, and it's most probable that it's an issue of the directory permissions, however I'd try the mode change, just in case.
精彩评论