Python os.major() Method

Python File(文件) 方法Python OS File/Directory Methods


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).

Syntax

major()The method syntax is as follows:

os.major(device)

Parameters

  • device-- Extract the device major number from the raw device number (using the st_dev or st_rdev field in stat).

Return Value

Returns the device major number.

Example

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

#!/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 output of the above program is:

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

Python File(文件) 方法Python OS File/Directory Methods

Other Extensions