File Permissions
Fredrik Lundh
effbot at telia.com
Thu Aug 31 18:24:24 EDT 2000
Lenny Self wrote:
> > 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>
>
> Thanks for your help but I only seem to be able to check whether or not the
> user running the script has "rwx" permissions. I am looking to find the
> permissions for owner/group/other, preferably in numeric mode.
did you try printing the "mode" value? I'm pretty sure
it does contain the "numeric mode" you're looking for.
try this:
st = os.stat(myfile)
mode = st[stat.ST_MODE]
print "mode is", octal(mode & 0777)
(looking in the stat module source file may also help; it's
in Python's Lib directory)
</F>
<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->
More information about the Python-list
mailing list