how to create new file using python
how can i cr开发者_如何学JAVAeate new file in /var/log directory using python language in OSX leopard? i tried to do it using os.open function but i get "permission denied"
thanks in advance
Only root can write in /var/log/
on Mac OS X...:
$ ls -ld /var/log
drwxr-xr-x 60 root wheel 2040 Oct 6 17:00 /var/log
Maybe consider using the syslog
module in the standard library...
It probably failed because /var/log has user set to root and group set to wheel. Try running your python code as root and it will probably work.
You can create the log file as root and then change the owner to the user your script is run as
# touch /var/log/mylogfile
# chown myuser /var/log/mylogfile
where mylogfile is your logfile and myuser is the user the script will be run as
also look into logrotate
精彩评论