Python os.supports_follow_symlinks Object

Python os.supports_follow_symlinks Object

  1. Syntax of Python os.supports_follow_symlinks Method
  2. Example 1: Use the os.supports_follow_symlinks Object in Python
  3. Example 2: Use the os.supports_follow_symlinks Object to Check if a Method Allows follow_symlinks Parameter

Python os.supports_follow_symlinks Object is an efficient way of checking whether a specific OS module allows a method to use their follow_symlinks parameter or not.

Many platforms provide various functionality, so we need to check if a function is available for use in Python.

os.supports_follow_symlinks

Parameters

It is a non-callable object, so no parameter is required.

Return

The return type of this method is a set object representing all the methods in the OS module that allows the use of their follow_symlinks argument.

import os

List = os.supports_follow_symlinks

print("Following are the method that allows their follow_symlinks parameter to be used: ", List)

Output:

Following are the method that allows their follow_symlinks parameter to be used:  {<built-in function link>, <built-in function access>, <built-in function chown>, <built-in function utime>, <built-in function stat>}

Note that to determine whether any Python method permits using its follow_symlinks parameter, we can use the in operator on the supports_follow_symlinks set.

import os

permission = os.stat in os.supports_follow_symlinks

print("Does it permit that its parameter is used? ", permission)

permission = os.lstat in os.supports_follow_symlinks

print("Does it permit that its parameter is used? ", permission)

Output:

Does it permit that its parameter is used?  True
Does it permit that its parameter is used?  False

In the above code, we are checking whether the os.stat() method allows its follow_symlinks parameter to be used on local platforms or not.

Musfirah Waseem avatar Musfirah Waseem avatar

Musfirah is a student of computer science from the best university in Pakistan. She has a knack for programming and everything related. She is a tech geek who loves to help people as much as possible.

LinkedIn

Related Article - Python OS

  • Python os.set_handle_inheritable() Method
  • Python os.set_inheritable() Method
  • Python os.stat_result Class
  • Python os.renames() Method
  • Python os.get_handle_inheritable Method
  • Python os.get_inheritable Method