How can I verify file existence in Python?

Learn to locate files using the os.path.isfile() function in Python.

By David Blaikie
September 6, 2016
Screenshot from "Verifying file existence in Python" Screenshot from "Verifying file existence in Python"

As a programmer in any language, it won’t be long before you run into a scenario that requires you to verify the existence of specific files. In this tutorial David Blaikie demonstrates how to locate files on your local system using the os.path.isfile() function in Python. David also uncovers the underlying principles of relative and absolute paths, which dictate file discovery in the present working directory. With this knowledge, developers and system administrators with a basic understanding of Python and file structures will be able to discover files quickly and effectively.

Click here to access our Python Learning Path and get more in-depth training.

Learn faster. Dig deeper. See farther.

Join the O'Reilly online learning platform. Get a free trial today and find answers on the fly, or master something new and useful.

Learn more

David Blaikie is a New York City-based engineer and trainer. He has taught Python, Advanced Python, Perl, and Advanced Perl at New York University’s School of Professional Studies, and has conducted corporate Python training for companies such as Google, Cisco, and Bloomberg, as well as for the U.S. Navy. David has been a release engineer at Google and a software developer for AppNexus, Conde Nast, and several startups. He is also the author of the bestselling O’Reilly book “Python Beyond the Basics: Object-Oriented Programming”. David’s contact information can be found at

Post topics: Open Source
Post tags: Questions