Mercurial > hg > cc > cirrus_work
changeset 123:43b0509e70c0
refactor to sort a module in an lmh package
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Thu, 28 Sep 2023 11:00:24 +0100 |
parents | 961aab080239 |
children | ddfb3e95a219 |
files | lib/python/cc/lmh/__init__.py lib/python/cc/lmh/sort_date.py |
diffstat | 2 files changed, 19 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/python/cc/lmh/__init__.py Thu Sep 28 11:00:24 2023 +0100 @@ -0,0 +1,5 @@ +'''Nothing to see here''' + +INITED = True + +from .sort_date import cdx_key
--- a/lib/python/cc/lmh/sort_date.py Thu Sep 28 10:54:12 2023 +0100 +++ b/lib/python/cc/lmh/sort_date.py Thu Sep 28 11:00:24 2023 +0100 @@ -128,15 +128,18 @@ print(dateTime.rstrip(),e,sep='\t',file=sys.stderr) return -fstr = sys.argv[1] +def main(fstr): -with open(fstr,"r") as ff: - # crucial that the following is done _after_ the file is opened - # with the default (utf-8) locale! - locale.setlocale(locale.LC_ALL, "C") - ctk=cmp_to_key(locale.strcoll) - for key, ts in sorted((kk for l in ff if (kk:=keyed(l)) is not None), - key=lambda x:x[0]): - print(key[0],key[1], - key[2].encode('ascii',errors='java_unicode').decode('ascii'), - ts,sep='\t') + with open(fstr,"r") as ff: + # crucial that the following is done _after_ the file is opened + # with the default (utf-8) locale! + locale.setlocale(locale.LC_ALL, "C") + ctk=cmp_to_key(locale.strcoll) + for key, ts in sorted((kk for l in ff if (kk:=keyed(l)) is not None), + key=lambda x:x[0]): + print(key[0],key[1], + key[2].encode('ascii',errors='java_unicode').decode('ascii'), + ts,sep='\t') + +if __name__ == '__main__': + sys.exit(main(fstr = sys.argv[1]))