Computer >> Computer tutorials >  >> Programming >> Python

How to compose a raw device number from the major and minor device numbers?


The method os.makedev(major, minor) composes a raw device number from the major and minor device numbers.

For example

import os, sys
path = "/var/www/html/foo.txt"
# Get the stat tuple
info = os.lstat(path)
# Get major and minor device number
major_dnum = os.major(info.st_dev)
minor_dnum = os.minor(info.st_dev)
dev_num = os.makedev(major_dnum, minor_dnum)
print "Device Number :", dev_num

Output

This will give the output:

Device Number : 105