How do I check whether a file exists without exceptions?

后端 未结 30 1857
北海茫月
北海茫月 2020-11-21 05:07

How do I check if a file exists or not, without using the try statement?

30条回答
  •  离开以前
    2020-11-21 05:32

    import os
    os.path.exists(path) # Returns whether the path (directory or file) exists or not
    os.path.isfile(path) # Returns whether the file exists or not
    

提交回复
热议问题