如何使用Python从原始设备号获取设备主号?

方法os.major(device)从原始设备号(通常是stat中的st_dev或st_rdev字段)中提取设备主号。

示例

要使用此方法,您应该具有原始设备号。您可以按以下方式使用它:

import os, sys
path = "/var/www/html/foo.txt"
# Now get the stat tuple
info = os.lstat(path)
# Get major device number
major_dnum = os.major(info.st_dev)
print "主设备号:", major_dnum

输出结果

这将给出输出:

主设备号: 0