File Permissions

VJ viji_mi10 at yahoo.com
Fri Mar 10 15:20:18 CET 2006


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




More information about the Python-list mailing list