Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีตรวจสอบ Permission ของไฟล์ใน Python

ใช้ os.access(path, mode) ตรวจสอบ permission ไฟล์

ตัวอย่าง

>>> import os
>>> os.access('my_file', os.R_OK)  # read access
True
>>> os.access('my_file', os.W_OK)  # write access
True
>>> os.access('my_file', os.X_OK)  # execute access
False
>>> os.access('my_file', os.F_OK)  # existance
True

หรือใช้ os.stat ดู status แบบละเอียด (ซับซ้อน ใช้ bitmasks) รายละเอียด