Python | os.supports_follow_symlinks object
Last Updated :
25 Jun, 2019
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 permit the use of their
follow_symlinks parameter. As different platforms provide different functionality,
follow_symlinks parameter might be supported on one platform but not supported on another.
os.supports_follow_symlinks
in Python is a set object which indicates which methods in the
OS module permit the use of their
follow_symlinks parameter
Whether a particular method permits the use of their
follow_symlinks parameter or not, can be checked using
in operator on
os.supports_follow_symlinks
.
For example:
Below expression checks whether
os.stat() method permits the use of their
follow_symlinks parameter or not when called on your local platform.
os.stat in os.supports_follow_symlinks
Syntax: os.supports_follow_symlinks
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 follow_symlinks parameter.
Code #1: Use of os.supports_follow_symlinks object
Python3
# Python program to explain os.supports_follow_symlinks object
# importing os module
import os
# Get the list of all methods
# which permits the use of their
# follow_symlinks parameter
methodList = os.supports_follow_symlinks
# Print the list
print(methodList)
Output:
{<built-in function stat>, <built-in function chown>,
<built-in function link>, <built-in function access>,
<built-in function utime>}
Code #2: Use of os.supports_follow_symlinks object to check if a particular method permits the use of their follow_symlinks parameter or not.
Python3
# Python program to explain os.supports_follow_symlinks object
# importing os module
import os
# Check whether os.stat() method
# permits the use of their
# follow_symlinks parameter or not
support = os.stat in os.supports_follow_symlinks
# Print result
print(support)
# Check whether os.fwalk() method
# permits the use of their
# follow_symlinks parameter or not
support = os.fwalk in os.supports_follow_symlinks
# Print result
print(support)