diff which.py @ 0:bcd62e6d822c

initial commit
author Jeff Hammel <k0scist@gmail.com>
date Mon, 20 Feb 2017 10:27:27 -0800
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/which.py	Mon Feb 20 10:27:27 2017 -0800
@@ -0,0 +1,21 @@
+#!/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()