- Mastering Python for Networking and Security
- José Manuel Ortega
- 54字
- 2021-07-16 17:40:00
Checking whether a specific path is a file or directory
We can check whether a certain string is a file or directory. For this, we can use the os.path.isfile() method, which returns True if it is a file and False if it is a directory:
>>> import os
>>> os.path.isfile("/")
False
>>> os.path.isfile("./main.py")
True