# HG changeset patch # User Jeff Hammel # Date 1529358521 25200 # Node ID 20aa4a6ef7193111c89c6ea77457997c6404ce88 # Parent 7191914724f09e249dc9a1d0c317c572715d9f39 python3 diff -r 7191914724f0 -r 20aa4a6ef719 python/lsex.py --- a/python/lsex.py Thu Jun 07 14:33:07 2018 -0700 +++ b/python/lsex.py Mon Jun 18 14:48:41 2018 -0700 @@ -1,10 +1,19 @@ #!/usr/bin/env python + import os import sys from optparse import OptionParser -# make sure duplicate path elements aren't printed twice +try: + # python 2 + string = (str, unicode) +except NameError: + # python 3 + string = (str,) + def ordered_set(alist): + """make sure duplicate path elements aren't printed twice""" + seen = set() new = [] for item in alist: @@ -25,7 +34,7 @@ if path is None: # use system path path = os.environ['PATH'] - if isinstance(path, basestring): + if isinstance(path, string): path = ordered_set(path.split(os.pathsep)) executables = [] @@ -35,7 +44,7 @@ if not os.path.isdir(i): continue files = [ os.path.join(i,j) for j in os.listdir(i) ] - files = filter(lambda x: os.access(x, os.X_OK), files) + files = list(filter(lambda x: os.access(x, os.X_OK), files)) files.sort() # just to make the output pretty executables.extend(files) return executables @@ -52,9 +61,8 @@ options, args = parser.parse_args() if options.names: - for i in sorted(executable_names()): - print i + print ('\n'.join(sorted(executable_names()))) sys.exit(0) - + for i in lsex(): - print i + print (i)