I am running a python script and very first thing to do is, it needs to check a permission of a file before it executes the whole program.
I am currently using os.system("stat -c '%a' /data/lims/LI")
is there a better way to do this without using os.system?
my actual coding is
checker = int(os.system("stat -c '%a' /data/lims/LI"))
if checker != 000:
print "pass"
I want to check the permission of a file which should be a number... something like 755, 750, and others
if it is a executable permission, than execute.
Yes, you can use Python's os.stat(path) or os.access(path) directly, e.g. to check it's executable
See Checking File Permissions in Linux with Python for more details.