You're viewing a single post. I have much more to say! The main blog page is a good starting point.

Which in python

If you want the functionality of which in a Python program, i.e. you want to look up the file system path for a given executable, you may use this simple function:

def which(e): return ([os.path.join(p, e) for p in os.environ['PATH'].split(os.pathsep) if os.path.exists(os.path.join(p, e))] + [None])[0]

The return value is the full path or None if the executable was not found. Easy enough!