comparison which.py @ 0:bcd62e6d822c

initial commit
author Jeff Hammel <k0scist@gmail.com>
date Mon, 20 Feb 2017 10:27:27 -0800
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bcd62e6d822c
1 #!/usr/bin/env python
2
3 import os
4 import sys
5
6 def which(fileName, path=os.environ['PATH']):
7 """python equivalent of which; should really be in the stdlib"""
8 dirs = path.split(os.pathsep)
9 for dir in dirs:
10 if os.path.isfile(os.path.join(dir, fileName)):
11 return os.path.join(dir, fileName)
12 if os.path.isfile(os.path.join(dir, fileName + ".exe")):
13 return os.path.join(dir, fileName + ".exe")
14
15 def main(args=sys.argv[1:]):
16 """CLI"""
17 for i in sys.argv[1:]:
18 print which(i)
19
20 if __name__ == '__main__':
21 main()