os.path.isdir
时间: 2023-11-23 07:05:26 浏览: 25
os.path.isdir(path) is a method in the Python programming language used to check whether a path exists and it points to a directory.
The method takes in one argument, which is the path to be checked. It returns True if the path exists and it points to a directory, and False otherwise.
Example:
```
import os
path = "/path/to/directory"
if os.path.isdir(path):
print("The path exists and it is a directory")
else:
print("The path does not exist or it is not a directory")
```
In this example, we import the os module and set the path variable to "/path/to/directory". We then use the os.path.isdir() method to check if the path exists and it points to a directory. If it does, we print "The path exists and it is a directory". Otherwise, we print "The path does not exist or it is not a directory".