Which one should I use to maximize performance?
os.path.isfile is quite a bit faster than
In : %timeit open('test_test.txt') 10000 loops, best of 3: 47.9 us per loop In : %timeit os.path.isfile('test_test.txt') 100000 loops, best of 3: 6.21 us per loop
But look at the run times. You need to open or check for a lot of files to have any practical impact on total run time for most applications.