Python Practice › OS Module Programs › Program 28
Check read permission
Write a Python program to check read and write permission on a path with os.access().
Output
readable: True writable: True missing: False
Approach
- Pass
os.R_OK/os.W_OK.
Solution
import os open("perm.txt", "w").close()print("readable:", os.access("perm.txt", os.R_OK))print("writable:", os.access("perm.txt", os.W_OK))print("missing:", os.access("nope.txt", os.F_OK))Output
readable: True writable: True missing: False
Learn the concept
New to this topic? Read the lesson, then come back.