如何使用Python从原始设备号中获取设备主要编号?
方法 os.major(device) 从原始设备号中提取设备主要编号(通常是 stat 中的 st_dev 或 st_rdev 字段)。
阅读更多:Python 教程
例子
要使用此方法,您应该有原始设备号。您可以按以下方式使用它:
import os, sys
path = "/var/www/html/foo.txt"
# 获取 stat 元组
info = os.lstat(path)
# 获取主要设备号
major_dnum = os.major(info.st_dev)
print "Major Device Number :", major_dnum
输出
这将给出输出:
Major Device Number : 0
极客教程