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 module to use command line arguments.
Create a file pointer and open the file which is passed in command line.
Initialize word count as zero.
For each line in file, split it into words and find number of the words in every line.
Sum the number of words in each line.
Display the total words in the file.
# Program to find the word count using command line arguments
# Developed by : HEMAVATHY S
# Register Number : 212223230076
import sys
count=0
with open(sys.argv[1],'r') as f1:
for i in fp:
words=i.split()
count+=len(words)
print("word count in file is",count)
Thus the program is written to find the word count from the contents of a file using command line arguments.