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

前端 未结 5 2046

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:56

    On Unix you have to split the PATH var.

    if any([os.path.exists(os.path.join(p,progname)) for p in os.environ["PATH"].split(":")]):
        do_something()
    

提交回复
热议问题