Below is a simple program of reading a file and reading how many 8s there are in the file:
import sys
if len(sys.argv) == 1:
print "ERROR: Please put a filename after your Python file!"
else:
myFile = sys.argv[1]
new = open(myFile)
numEight = 0
text = new.read()
line = len(text.splitlines())
for char in text:
if char == "8":
numEight = numEight + 1
print "There are ", numEight, "in this text file"
Question is, how do you create a try catch if the filename entered is not correct? or, is there a way to do that in an elif statement?