开发者

how to create new file using python

开发者 https://www.devze.com 2022-12-08 01:39 出处:网络
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\"

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

0

精彩评论

暂无评论...
验证码 换一张
取 消