Getting File Permissions
Andrei Kulakov
ak at silmarill.org
Mon May 13 11:48:31 EDT 2002
In article <f0fd5987.0205130436.5e6a6a64 at posting.google.com>,
Garry Taylor wrote:
> 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
>
You have to import stat.
>
> 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
--
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org
More information about the Python-list
mailing list