view which.py @ 1:f4b604d44ff5 default tip

rename console script to avoid import madness
author Jeff Hammel <k0scist@gmail.com>
date Tue, 04 Jul 2017 20:56:43 -0700
parents bcd62e6d822c
children
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")

def main(args=sys.argv[1:]):
    """CLI"""
    for i in sys.argv[1:]:
        print which(i)

if __name__ == '__main__':
    main()