How do I check whether a file exists without exceptions?

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

    Prefer the try statement. It's considered better style and avoids race conditions.

    Don't take my word for it. There's plenty of support for this theory. Here's a couple:

    • Style: Section "Handling unusual conditions" of http://allendowney.com/sd/notes/notes11.txt
    • Avoiding Race Conditions

提交回复
热议问题