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

20.10. The stat module: file statistics

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_MODEThe file's permissions.
ST_INOThe i-node number.
ST_DEVThe device number.
ST_NLINKThe number of hard links.
ST_UIDThe user ID.
ST_GIDThe group ID.
ST_SIZEThe current size in bytes.
ST_ATIMEThe epoch time of last access (see the time module for interpretation of times).
ST_MTIMEThe epoch time of last modification.
ST_CTIMEThe epoch time of the file's creation.

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_ISDIR(m)Is this a directory?
S_ISCHR(m)Is this a character device?
S_ISBLK(m)Is this a block device?
S_ISREG(m)Is this an ordinary file?
S_ISFIFO(m)Is this a FIFO?
S_ISLNK(m)Is this a soft (symbolic) link?
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():

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