sorting pathnames by basename

Erik Price erikprice at mac.com
Tue Aug 20 07:18:08 EDT 2002


On Tuesday, August 20, 2002, at 12:39  AM, Erik Price wrote:

> #!/usr/bin/python
> #
> # basenamesort.py
> #
> # Unix-style filter that sorts a newline-separated
> # list of files by the file basename
> #
> # Example usage:  cat files.txt | basenamesort.py
>
> import sys
> import os
>
> tempDict = {}
>
> for line in sys.stdin.xreadlines():
>   tempDict[os.path.basename(line)] = line.rstrip()
>
> sorted = tempDict.keys()

sorted.sort()

> for key in sorted:
>   print tempDict[key]



Whoops.  It figures that I would forget the part that actually does the 
sorting.  I added it above (the "sorted.sort()" line).



Erik



--
Erik Price

email: erikprice at mac.com
jabber: erikprice at jabber.org
>
> _______________________________________________
> gnhlug-discuss mailing list
> gnhlug-discuss at mail.gnhlug.org
> http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
>




More information about the gnhlug-discuss mailing list