Skip to content

Commit

Permalink
python 3 for sum
Browse files Browse the repository at this point in the history
  • Loading branch information
mjpost committed Aug 23, 2021
1 parent 4e1589c commit ecf6834
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#!/usr/bin/python
#!/usr/bin/python3

import re
import sys
import locale
import argparse

locale.setlocale(locale.LC_ALL, 'en_US')

parser = argparse.ArgumentParser(description='Sum numbers in a column of text')
parser.add_argument('col', nargs='?', type=int, default=-1, help='Which column? (0-indexed)')
parser.add_argument('-p', dest='pretty', default=False, action='store_true', help='Pretty-print')
Expand All @@ -21,8 +18,8 @@ for line in sys.stdin:
tokens = re.split(r'\s+', line.rstrip())
total += float(tokens[args.col])

sum = locale.format("%g", total, grouping=args.pretty)
sum = total
if args.verbose:
print "%s (%d lines)" % (sum, line_count)
print("%s (%d lines)" % (sum, line_count))
else:
print sum
print(sum)

0 comments on commit ecf6834

Please sign in to comment.