Getting File Permissions

Garry Taylor gtaylor at lowebroadway.com
Mon May 13 08:36:28 EDT 2002


Hi,
This has been asked before, but I cannot get the solution to work,
quite simply, I want to get the permissions for a file, ideally in a
rwx-rwx-rwx format, but anything I can get will do!

I have tried:

st = os.stat('/home/gaz')
mode = st[stat.ST_MODE]
print "mode is", octal(mode & 0777)

but it errors with:

Traceback (most recent call last):
  File "filepermissions.py", line 5, in ?
    mode = st[stat.ST_MODE]
NameError: name 'stat' is not defined

I know this must seem really simple, but I cannot find anything that
actually works, do I have to import something which not obvious? octal
does not even seem to be a valid command. Is there a different way to
get this information, a module or something?

Thanks a lot in advance.

Garry



More information about the Python-list mailing list