Python os.major()方法

Python的major()方法从原始设备号(通常是statst_devst_rdev字段)提取设备主要号码。

语法

以下是major()方法的语法 -

os.major(device)

参数

  • device - 这是一个原始设备号(通常来自statst_devst_rdev字段)。

返回值

  • 此方法返回设备主号。

示例

以下示例显示了major()方法的用法。

#!/usr/bin/python3
import os, sys

path = "/var/www/html/foo.txt"

# Now get  the touple
info = os.lstat(path)

# Get major and minor device number
major_dnum = os.major(info.st_dev)
minor_dnum = os.minor(info.st_dev)

print ("Major Device Number :", major_dnum)
print ("Minor Device Number :", minor_dnum)

执行上面代码后,将得到以下结果 -

Major Device Number : 0
Minor Device Number : 103

上一篇: Python os模块方法 下一篇: Python异常处理