To write a python program for getting the word count from the contents of a file using command line arguments.
PC Anaconda - Python 3.7
import sys
Open file using open().
Use for loop
Use len to count number of words.
Give print.
End of the program
import sys
count= 0
with open(sys.argv[1],'r') as f1:
for line in f1:
word= line.split()
count += len(word)
print("word count in file = ",count)
Thus the program is written to find the word count from the contents of a file using command line arguments.