Re: How to control permission of file?
- From: Schüle Daniel <uval@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 30 Jun 2006 23:34:05 +0200
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
.
- Follow-Ups:
- Re: How to control permission of file?
- From: Grant Edwards
- Re: How to control permission of file?
- Prev by Date: Re: Import bug: Module executed twice when imported!
- Next by Date: Re: How to control permission of file?
- Previous by thread: Re: Import bug: Module executed twice when imported!
- Next by thread: Re: How to control permission of file?
- Index(es):
Relevant Pages
|