# How can I get a file's permission mask using Python?

PythonServer Side ProgrammingProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

To get stat of a file, method stat() from the os module can be used. It performs a stat system call on the given path. For example,

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

This function takes the name of a file, and returns a 10-member tuple with the following contents:

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

The mode variable gives you the information about file permissions. You can get it by st[0]. You can read more about interpreting the tuple here: http://effbot.org/zone/python-fileinfo.htm

Updated on 03-Oct-2019 05:57:13