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
Create a text file in a specific loaction of interest.
On the same location as the text file, create a python program file.
In python Program, import sys and open a text file with argument "sys.argv[1]"
using read() and split(), split the lines in the file into a sequence of words.
using len() count the number of words in the text file.
In command prompt, initiate python followed by program name and text file name to get the output.
'''
# Python program for getting the word count from the contents of a file using command line arguments.
# Developed By: NITHISHWAR S
# RegisterNumber:21002766
'''
import sys
fp = open(sys.argv[1])
data=fp.read()
words=data.split()
print("no.of words",len(words))
Thus the program is written to find the word count from the contents of a file using command line arguments.