effbot at telia.com
Fri Sep 1 00:24:24 CEST 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.
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)
<!-- (the eff-bot guide to) the standard python library:
More information about the Python-list