How to check if a file exists using Python?

Please explain me how to check whether a file exists using Python.

Comments

  • You can use the os.path.isfile function:

    import os.path
    os.path.isfile(file_path_with_name)
    
  • swagrexx_17swagrexx_17 Boston, MA

    Yes, that does make sense. I've never heard of that one though, thanks for the new technique!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories