Monday, 9 May 2016

python - Pythonic way to check if a file exists?




Which is the preferred way to check if a file exists and if not create it?


Answer



To check if a path is an existing file:



os.path.isfile(path)




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.



No comments:

Post a Comment