Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python3 os.major() Method

Python3 os.major() Method

Python3 OS File/Directory Methods Python3 OS File/Directory Methods


Overview

The os.major() method extracts the device major number from a raw device number (using the st_dev or st_rdev field in stat).

Syntax

The **major()** method syntax is as follows:


os.major(device)

Parameters

Return Value

Returns the device major number.

Example

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


#!/usr/bin/python3

import os, sys

path = "/var/www/html/foo.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 设备号 :", major_dnum)
print ("Minor 设备号 :", minor_dnum)

The output of the above program is:


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

Python3 OS File/Directory Methods Python3 OS File/Directory Methods