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
Initially make count = 0
Open the content file using command line arguments.
By using for loop name the function as "line"
Split the line using .split
Count the length of the word and print it
Program for getting the word count from the contents of a file using command line arguments
Developed by: GANESH R
RegisterNumber: 212222240029
import sys
fp=open(sys.argv[1],'r')
count=0
for line in fp:
words=line.split()
count+=len(words)
print("Number 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.