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.
##Developed by : YOGABHARATHI.S
##Register number :22009015
import sys
with open(sys.argv[1],'r') as f:
num_words =0
for i in f:
word =i.split()
num_words += len(word)
print("Number of words={}".format(num_words))
Thus the program is written to find the word count from the contents of a file using command line arguments.