Open In App

Python | os.path.ismount() method

Last Updated : 24 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

os.path module is sub module of Python OS Module in Python used for common path name manipulation.

os.path.ismount() method in Python is used to check whether the given path is a mount point or not. A mount point is a point in a file system where a different file system has been mounted.

os.path.ismount() Syntax in Python

Syntax: os.path.ismount(path)

Parameter:

  • path: A path-like object representing a file system path. A path-like object is either a string or bytes object representing a path.

Return Type: This method returns a Boolean value of class bool. This method returns True if the given path is a mount point, otherwise returns False.

Python os.path.ismount() Method Example

Below, we are explaing the example of Python mount, those are following.

On Linux system, the partitions and their mount points information can be displayed using the df command.

For example:

Mount point informations

Check if Paths are Mount Points using Python Mount (On Unix)

In this example , below Python code uses the os.path module to check if “/run” and “/dev” are mount points. It determines whether each path corresponds to a mounted file system and check for the “/dev” path.

Python3




# importing os.path module 
import os.path
   
# Path 
path = "/run"
   
# Check whether the 
# given path is a
# mount point or not
ismount = os.path.ismount(path)
   
# Path 
path = "/dev"
   
# Check whether the 
# given path is a
# mount point or not
ismount = os.path.ismount(path)
print(ismount)


Output

True
True


Check if Paths are Mount Points using Python Mount (On Windows)

In this example, Python code uses the os.path module to check if “C:” is a mount point on Windows. It determines whether the specified path corresponds to a drive letter root, and indicating whether “C:” is a mount point or not.

Python3




# importing os.path module 
import os.path
   
# On Windows, a drive letter root
# and a share UNC are always
# mount points Path 
path = "C:"
   
# Check whether the 
# given path is a
# mount point or not
ismount = os.path.ismount(path)
print(ismount)


Output

True




Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads