Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Cách lấy permission mask của file bằng Python?


Để lấy stat file, dùng phương thức stat() từ module os. Nó thực hiện system call stat trên path. Ví dụ:

import os
st = os.stat("file.dat")

Hàm nhận tên file, trả về tuple 10 phần tử:

(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime)

Biến mode cho thông tin permission file. Lấy bằng st[0]. Xem thêm giải thích tuple tại: https://effbot.org/zone/python-fileinfo.htm