2024FALLcse160Lectures/bigos/lecture20241119/fileio_census/file-read01.py

29 lines
656 B
Python

#!/usr/bin/python3
## ============================ One time initializations ========================
fileName = "testdata.txt"
## ============================ Open and process file(s) ========================
try:
inFile = open(fileName,'r')
count = 1
runFlag = True
while(runFlag): # Process while true
# print(count,line.rstrip("\n"))
line = inFile.readline()
if line == "":
runFlag == False
else:
line = line.rstrip("\n")
print(count,line)
count = count + 1
except:
print("Some error occurred. Ending here")
exit(-1)
inFile.close()