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
fname to represent the file name given
with open function to open a file
text files words are splitted using split()
using for loop to count the char
char has been counted and output has been printed
#Program to find the Word Count using command line arguments
#Developed by : Allen Joveth P
#Register Number : 23009582
fname=input("enter the file name")
num_words=0
with open(fname,'r') as f:
for line in f:
words=line.split()
num_words+=len(words)
print('Number of words: ',num_words)
Thus the program is written to find the word count from the contents of a file using command line arguments.