Mercurial > hg > config
view python/which.py @ 842:03f9657514e9
while we might not want Octave *that* much, we will never want OCAML
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 09 Jul 2017 15:01:16 -0700 |
parents | e4221e45d6c1 |
children | e7ab4cf29f7b |
line wrap: on
line source
#!/usr/bin/env python import os import sys def which(fileName, path=os.environ['PATH']): """python equivalent of which; should really be in the stdlib""" dirs = path.split(os.pathsep) for dir in dirs: if os.path.isfile(os.path.join(dir, fileName)): return os.path.join(dir, fileName) if os.path.isfile(os.path.join(dir, fileName + ".exe")): return os.path.join(dir, fileName + ".exe") if __name__ == '__main__': for i in sys.argv[1:]: print which(i)