Python os.major() Method
os.major() Overview
The os.major() method is used to extract the device major number from the raw device number (using the st_dev or st_rdev field in stat).
os.major() Syntax
The major() method syntax format is as follows.
os.major(device)
os.major() Parameters
- device – Extracts the device major number from the original device number (using the st_dev or st_rdev field in stat).
os.major() Return Value
Returns the device major number.
os.major() Demo#1
The following example demonstrates the use of the major() method:
#!/usr/bin/python3
import os, sys
path = "/root/apidemos.com.txt"
# Get tuple
info = os.lstat(path)
# Get major and minor device numbers
major_dnum = os.major(info.st_dev)
minor_dnum = os.minor(info.st_dev)
print ("Major Device Number from os.major:", major_dnum)
print ("Minor device number from os.minor:", minor_dnum)
Output: