-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwordcount
More file actions
executable file
·32 lines (25 loc) · 778 Bytes
/
wordcount
File metadata and controls
executable file
·32 lines (25 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#! /usr/bin/env python
import sys
import argparse
import wordcount_lib
def main():
p = argparse.ArgumentParser()
p.add_argument('filenames', nargs='+')
args = p.parse_args()
total_words = 0
total_lines = 0
total_chars = 0
for filename in args.filenames:
try:
chars, words, lines = wordcount_lib.consume(filename)
except IOError:
print('error - %s does not exist!' % filename, file=sys.stderr)
continue
# track total
total_words += words
total_lines += lines
total_chars += chars
print('%d\t%d\t%d\tin %d files' % (total_chars, total_words, total_lines,
len(args.filenames)))
if __name__ == '__main__':
main()