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

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...