You're viewing a single post. I have much more to say! The main blog page is a good starting point.
Saturday, June 2, 2007 ★ 17:12 ★ Category Programming
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!
Random photo from Prague (July, 2005)
Wouter Bolsterlee, also known as uws, a postmodern geek living in the Netherlands. Read more about me…
Unless stated otherwise, all material on this site is available under a Creative Commons Share-Alike license.