A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/python/os_major.htm below:

Python os.major() Method

Python os.major() Method

The Python os.major() method extracts the device major number from a raw device number. This raw device number is obtained by either "st_dev" or "st_rdev" field of "os.stat_result" object returned by os.stat() method.

The os.stat() method is used to get the status of file descriptor.

NOTE: In Unix-like operating systems, every file is associated with a device number. This number is composed of two parts namely major and minor. The major number specifies the driver associated with the device, whereas the minor number is used by the driver to differentiate between different devices it controls.

Syntax

The syntax for os.major() method is shown below −

os.major(device)
Parameters

The Python os.major() method accepts a single parameter −

Return Value

The Python os.major() method returns the device major number.

Example

The following example illustrates the use of major() method. Here, we are retrieving the major device number from the value obtained by "st_dev" attribute.

import os, sys
path = "newFile.txt"

# Now get the touple
info = os.lstat(path)

# Get major device number
major_dnum = os.major(info.st_dev)
print ("Major Device Number:", major_dnum)

When we run above program, it produces following result −

Major Device Number: 8
Example

In this example, we are extracting the major device number of a file descriptor from the value obtained by "st_rdev" attribute.

import os
import stat

# path of terminal character device
deviceStat = os.stat("/home/shriansh/Python/tmp/new").st_rdev
mNumber = os.major(deviceStat)
print(f"The major device number for terminal character device: {mNumber}")

On executing the above program, it produces the following output −

The major device number for terminal character device: 0

python_files_io.htm


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4