Quantcast
Channel: How do I check whether a file exists without exceptions? - Stack Overflow
Viewing all articles
Browse latest Browse all 46

Answer by KaiBuxe for How do I check whether a file exists without exceptions?

$
0
0

In 2016 the best way is still using os.path.isfile:

>>> os.path.isfile('/path/to/some/file.txt')

Or in Python 3 you can use pathlib:

import pathlibpath = pathlib.Path('/path/to/some/file.txt')if path.is_file():    ...

Viewing all articles
Browse latest Browse all 46

Trending Articles