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.
#DEVELOPED BY : LAVANYA S
#REGISTER NUMBER: 212223230112
import sys
fp=open(sys.argv[1])
wordcount=0
for i in fp:
words=i.split()
wordcount+=len(words)
print("Total no of words in file is",wordcount)
fp.close()
Thus the program is written to find the word count from the contents of a file using command line arguments.