os.path.exists() for files in your Path?

前端 未结 5 2042

I commonly use os.path.exists() to check if a file is there before doing anything with it.

I\'ve run across a situation where I\'m calling a executable that

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-04 07:35

    Please note that checking for existance and then opening is always open to race-conditions. The file can disappear between your program's check and its next access of the file, since other programs continue to run on the machine.

    Thus there might still be an exception being thrown, even though your code is "certain" that the file exists. This is, after all, why they're called exceptions.

提交回复
热议问题