Re: How to control permission of file?



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

.



Relevant Pages

  • Re: How to control permission of file?
    ... Under Unix, it's a bitmapped value that determines what the ... access permissions are for the file. ... other-read, other-write, other-execute, etc. ... how to control a file's mode when it was created by the builtin ...
    (comp.lang.python)
  • Re: Apple Computer sides with Satan
    ... > Unix never used to have as fine a level of control over user ... > permissions as some other systems, but I suspect improvements have ... I don't think the permissions system itself has changed significantly ... At least with the Unix variants I was dealing with 20 ...
    (sci.astro.amateur)
  • How to control permission of file?
    ... When one opens a file for writing, ... does one control that file's permissions (it's "mode" in Unix ...
    (comp.lang.python)
  • Re: How to control permission of file?
    ... does one control that file's permissions (it's "mode" in Unix ... It returns a file descriptor, and if you need a file object you can use ...
    (comp.lang.python)