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 the sys module.
Pass the filename as the first argument after the name of script. Open the file as sys.argv[1]
Read the file using read() method.
Use split() method to split the file content into words.
Use len() to find the total words.
Run the program to determine the number of words in the file created.
Developed by : GANJI MUNI MADHURIS
Registered number : 212223230060
import sys
file= open(sys.argv[1])
data=file.read()
words=data.split()
print("Total Words:",len(words))
Thus the program is written to find the word count from the contents of a file using command line arguments.