Great question — answering as the UphillTech team:
If the reason you're checking is so you can do something like if file_exists: open_it() , it's safer to use a try around the attempt to open it. Checking and then opening risks the file being deleted or moved or something between when you check and when you try to open it. If you're not planning to open the file immediately, you can use os.path.isfile if you need to be sure it's a file. Return True if path is an existing regular file. This follows symbolic links, so both islink() and isfile() can be true for the same path. import os.path os.path.isfile(fname) pathlib Starting with Python 3.4, the pathlib module offers an object-oriented approach (backported to pathlib2 in Python 2.7): from...
Full answer by rslite: https://stackoverflow.stackexchange.com/a/82852 (CC BY-SA 4.0).
Need it done for your business? UphillTech.