
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How can I get a file's permission mask using Python?
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
- Related Articles
- How can I get the current week using Python?
- How to change the permission of a file using Python?
- How to change the permission of a directory using Python?
- How can I get a list of locally installed Python modules?
- Can I get a job with a Python certificate?
- How can I get last 4 characters of a string in Python?
- How can I get enum possible values in a MySQL database using PHP?
- How i can replace number with string using Python?
- How can I get the list of files in a directory using C/C++?
- Python program to mask a list using values from another list
- How can I scroll a web page using selenium webdriver in python?
- How can I parse a website using Selenium and Beautifulsoup in python?
- How can I clear text of a textbox using Python Selenium WebDriver?
- Can I get Age using BirthDate column in a MySQL query?
- How can I get the ID of an DOM element using jQuery?

Advertisements