Next / Previous / Contents / TCC Help System / NM Tech homepage

28.8. stat: Interpretation of file status

The stat module contains a number of variables used in encoding and decoding various items returned by certain methods in the os module, such as stat() and chmod().

First, there are constants for indexing the components of a “status tuple” such as that returned by os.stat():

ST_ATIME The epoch time of last access (see the time module for interpretation of times).
ST_CTIMEThe epoch time of the file's last status change.
ST_DEVThe device number.
ST_GIDThe group ID.
ST_INOThe i-node number.
ST_MODEThe file's permissions.
ST_MTIMEThe epoch time of last modification.
ST_NLINKThe number of hard links.
ST_SIZEThe current size in bytes.
ST_UIDThe user ID.

The following functions are defined in the stat module for testing a mode value m, where m is the ST_MODE element of the status tuple. Each function is a predicate:

S_ISBLK(m) Is this a block device?
S_ISCHR(m) Is this a character device?
S_ISDIR(m) Is this a directory?
S_ISFIFO(m) Is this a FIFO?
S_ISLNK(m) Is this a soft (symbolic) link?
S_ISREG(m) Is this an ordinary file?
S_ISSOCK(m) Is this a socket?

These constants are defined for use as mask values in testing and assembling permission values such as those returned by os.stat() in Section 28.7, “os: The operating system interface”.

S_IRGRPGroup read permission.
S_IROTHWorld read permission.
S_IRUSROwner read permission.
S_ISGIDSGID (set group ID) bit.
S_ISUIDSUID (set user ID) bit.
S_IWGRPGroup write permission.
S_IWOTHWorld write permission.
S_IWUSROwner write permission.
S_IXGRPGroup execute permission.
S_IXOTHWorld execute permission.
S_IXUSROwner execute permission.