Mastering Python for Networking and Security
上QQ阅读APP看书,第一时间看更新

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