Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

terminal exercises

Views: 2497
1
#! /usr/bin/python3
2
3
import sys
4
5
## The argument vector is a list of command line inputs
6
7
if len(sys.argv)>1:
8
9
filename = sys.argv[1]
10
11
file_h = open(filename,"r")
12
content = file_h.read()
13
else:
14
#No command line input! REad from stdin.
15
16
content = sys.stdin.read()
17
18
19
wordcount = len(content.split())
20
linecount = content.count("\n")
21
charcount = len(content)
22
print("{} {} {}".format(linecount,wordcount,charcount))
23
24
25