Latest web development tutorials

Python os.major () method

Python File (File) method Python 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/python
# -*- coding: UTF-8 -*-

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

Python File (File) method Python OS file / directory methods