How do I check whether a file exists without exceptions?

后端 未结 30 2781
北海茫月
北海茫月 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:23

    If you imported NumPy already for other purposes then there is no need to import other libraries like pathlib, os, paths, etc.

    import numpy as np
    np.DataSource().exists("path/to/your/file")
    

    This will return true or false based on its existence.

提交回复
热议问题