all Python 3statfunction
stat.S_ISBLK()
file type
Checks from st_mode that the object is a block device, such as the disk /dev/sda or a partition.
Syntax
stat.S_ISBLK(os.stat(path).st_mode)
Block and character devices are different types: /dev/null is a character device, so S_ISBLK gives False for it. Block devices live mostly in /dev on Linux and macOS; inside a container and on Windows you usually see none at all, so a hand-built mode S_IFBLK | permissions is the way to demonstrate it.
Examples
import os, stat
print(stat.S_ISBLK(os.stat(os.devnull).st_mode)) # → False — /dev/null символьное
mode = stat.S_IFBLK | 0o660
print(stat.S_ISBLK(mode), stat.filemode(mode)) # → True brw-rw----
See also
Open in the full glossarydocs.python.orgReport an inaccuracy