How to control permission of file?
Schüle Daniel
uval at rz.uni-karlsruhe.de
Fri Jun 30 17:34:05 EDT 2006
Grant Edwards schrieb:
> When one open()s a file (that doesn't exist) for writing , how
> does one control that file's permissions (it's "mode" in Unix
> terms).
what do you mean by "contor file's mode"?
usually you try to open and if you are not allowed
you will get the exception
>>> try:
... f = file("/etc/shadow")
... print f.read()
... except IOError, e:
... print e
...
[Errno 13] Permission denied: '/etc/shadow'
>>>
if you want to know more about file attributes
use os.stat and constants from stat module
>>> import os
>>> os.stat("/etc/shadow")
(33184, 245390L, 771L, 1, 0, 15, 604L, 1151702662, 1149675585, 1149675585)
>>>
>>> import stat
>>> stat.ST_SIZE
6
>>> os.stat("/etc/shadow")[stat.ST_SIZE]
604L
>>>
http://docs.python.org/lib/module-stat.html
hth, Daniel
More information about the Python-list
mailing list