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
Open the file with sys.argv[1]
Use the for loop to select the content in file
Use split function to to separate the file content into words or strings
Count the length of the words using len
Print the number of words
Program for getting the word count from the contents of a file using command line arguments
Developed by: Santhosh L
RegisterNumber: 212222100046
import sys
fp=open(sys.argv[1], 'r')
count=0
for line in fp:
list1=line.split()
count+=len(list1)
print("No of words in a file",count)
Thus the program is written to find the word count from the contents of a file using command line arguments.