File Permissions
Fredrik Lundh
effbot at telia.com
Thu Aug 31 13:57:13 EDT 2000
Lenny Self <lenny at squiggie.com> wrote:
> After looking though the Python Essential Reference and the Python Library
> Reference I am still stumped on how to get a file's permissions. I have been
> able to get a file's owner and group IDs using the os.stat function but it
> doesn't seem to give me the file's permissions.
>
> Can someone help me out? I'd really appreciate it.
the first member of the stat tuple (ST_MODE) contains
the permissions, as a bitmask.
you can use the functions and macros in the "stat" module
to decipher them.
st = os.stat(myfile)
mode = st[stat.ST_MODE]
if mode & stat.ST_IREAD:
print "readable"
if mode & stat.ST_IWRITE:
print "writable"
if mode & stat.ST_IEXEC:
print "executable"
(etc)
</F>
<!-- daily news from the python universe:
http://www.pythonware.com/daily/index.htm
-->
More information about the Python-list
mailing list