Open In App

Python | os.supports_dir_fd object

Last Updated : 28 Oct, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality.

Some method in Os module takes a dir_fd parameter. As different platforms provide different functionality, dir_fd parameter might be available on one platform but unavailable on another. os.supports_dir_fd method in Python is a set object which indicates which methods in the OS module permit the use of their dir_fd parameter.

To check whether a particular method permits the use of its dir_fd parameter or not, can be checked using in operator on os.supports_dir_fd .
For example:
Below expression checks whether the dir_fd parameter of os.stat() method is locally available or not

os.stat in os.supports_dir_fd

Syntax: os.supports_dir_fd

Parameter: This is a non callable set object. Hence, no parameter is required.

Return Type: This method returns a set object which represents the methods in the OS module, which permits the use of their dir_fd parameter.

Code #1: Use of os.supports_dir_fd object to get the list of methods which permits the use of their dir_fd parameter




# Python program to explain os.supports_dir_fd object  
  
# importing os module 
import os
  
  
# Get the list of all methods
# who permits the use of
# their dir_fd parameter
methodList = os.supports_dir_fd
  
# Print the list
print(methodList)


Output:

{<built-in function symlink>, <built-in function stat>, <built-in function chown>,
<built-in function link>, <built-in function readlink>, <built-in function access>,
<built-in function rename>, <built-in function chmod>, <built-in function utime>,
<built-in function mknod>, <built-in function unlink>, <built-in function mkdir>,
<built-in function mkfifo>, <built-in function rmdir>, <built-in function open>}
Code #2: Use of os.supports_dir_fd object to check if a particular method permits the use of its dir_fd parameter or not




# Python program to explain os.supports_dir_fd object  
  
# importing os module 
import os
  
  
  
# Check whether os.stat() method
# permits the use of its dir_fd
# parameter or not
support = os.stat in os.supports_dir_fd
  
# Print result
print(support)
  
  
# Check whether os.lstat() method
# permits the use of its dir_fd
# parameter or not
support = os.lstat in os.supports_dir_fd
  
# Print result
print(support)


Output:

True
False


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads