On 09Feb2017 11:59, Wildman <best_...@yahoo.com> wrote:
Here is a method I frequently use to replace the which
command. (air code)

import os
pathlist = os.environ["PATH"].split(":")

def which(target)
   for p in pathlist:
       fullpath = p + "/" + target
       if os.path.isfile(fullpath):
           return fullpath, True
   return "", False

Cleaner is to return the path if found, or None if not.

target, found = which("pandoc")
if found:
   target will contain the full path to pandoc
else:
   pandoc was not found

You want to check for execute permssion too.

Cheers,
Cameron Simpson <c...@zip.com.au>
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to