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
Start the program.
Create a text file in which words has to be counted.
Open python file in visual studio code.
Execute the program.
Print the output.
End the program.
#Command line arguments - word count
#Developed by: SANDHIYA R
#Register number:212223240146
import sys
count=0
with open(sys.srgv[1],'r')as f1:
for line in f1:
word=line.split()
count += len(word)
print("word count in file = ",count)
Thus the program is written to find the word count from the contents of a file using command line arguments.