Check read permission

EasyOS Module Programs · 28 of 49

Write a Python program to check read and write permission on a path with os.access().

Advertisement
Output
readable: True
writable: True
missing: False

Approach

  1. Pass os.R_OK / os.W_OK.

Solution

Python
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.

More os module programs

← All 49 OS Module Programs

Leave a Comment