A nice simplification from @dpford

os.path.isfile(foo) is more consise than

os.path.exists(foo) and not os.path.isdir(foo)