Latest web development tutorials

Python3 os.major () method

Python3 OS file / directory methods Python3 OS file / directory methods


Outline

os.major () method for extracting device major number from a raw device number (using stat in st_dev or st_rdev field).

grammar

major () method syntax is as follows:

os.major(device)

parameter

  • device - the original number as extraction device major number (or use the stat in st_dev st_rdev field).

return value

Device major numbers.

Examples

The following example demonstrates the major () method of use:

#!/usr/bin/python3

import os, sys

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

# 获取元组
info = os.lstat(path)

# 获取 major 和 minor 设备号
major_dnum = os.major(info.st_dev)
minor_dnum = os.minor(info.st_dev)

print ("Major 设备号 :", major_dnum)
print ("Minor 设备号 :", minor_dnum)

The above program output is:

Major 设备号 : 0
Minor 设备号 : 103

Python3 OS file / directory methods Python3 OS file / directory methods