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
Get the file name using command arguments
Now read the content in the file
use split()
Now read the no.of words in file
Print number of words present in given file
End of the program
'''
Python program for getting the word count from the contents of a file using command line arguments.
Developed by: R.Guruprasad
Ref no:22006697
'''
import sys
count = {}
with open(sys.argv[1], 'r') as f:
for line in f:
for word in line.split():
if word not in count:
count[word] = 1
else:
count[word] += 1
print(count)
f.close()
Thus the program is written to find the word count from the contents of a file using command line arguments.