os.access(path, mode) method returns True if access is allowed on path, False if not.
available modes are :
- os.F_OK - test the existence of path.
- os.R_OK - test the readability of path.
- os.W_OK - test the writability of path.
- os.X_OK - test if path can be executed.
for example, checking file /tmp/test.sh has execute permission
ls -l /tmp/temp.sh
-rw-r--r-- 1 * * 0 Mar 2 12:05 /tmp/temp.sh
os.access('/tmp/temp.sh',os.X_OK)
False
after changing the file permission to +x
chmod +x /tmp/temp.sh
ls -l /tmp/temp.sh
-rwxr-xr-x 1 * * 0 Mar 2 12:05 /tmp/temp.sh
os.access('/tmp/temp.sh',os.X_OK)
True