File Permissions

Sebastjan Trepca trepca at gmail.com
Fri Mar 10 15:33:57 CET 2006


Those constants are in stat module so add "import stat" before the program.

On 10 Mar 2006 06:20:18 -0800, VJ <viji_mi10 at yahoo.com> wrote:
> Hi All
>
> I need to get the user permission of a file using python. I was trying
> the following code which i found on google grups
>
>  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"
>
> I am getting a error saying
>
> " Traceback (most recent call last):
>   File "./test.py", line 23, in ?
>     if mode & stat.ST_IREAD:
> AttributeError: 'module' object has no attribute 'ST_IREAD' "
>
> any idea how to resolve this error ??
>
> Basically i want to write into a file .If the permissions are not there
> then print a error message.
> How do i achive this ???
>
> Thanks,
> VJ
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list