I am trying to read in every line from a given file and check (amongst other things) that the 3rd character of every line is a ';' (a semi colon). The files i make to go into my database needs to have every line with a two letter identifier followed by a semi colon.
The issue I am having is that the while loop goes through every line fine and does examine the semi colon correctly, but always reports that there is a problem with the last line of the file, because it is whitespace...
I have tried stripping lines, and getting the file loop to run only when the line has characters in it... but this seems to disable the while loop from working at all.
See code Below.
Thanks in advance!
Pete
The issue I am having is that the while loop goes through every line fine and does examine the semi colon correctly, but always reports that there is a problem with the last line of the file, because it is whitespace...
I have tried stripping lines, and getting the file loop to run only when the line has characters in it... but this seems to disable the while loop from working at all.
See code Below.
Code:
# takes in each individual line of the file
line = fileIN.readline()
# counter
x = 1
# while loop
while line:
# != None:
# != re.sub("\n\s*\n*", "\n", line):
line = fileIN.readline()
line.strip()
# checks that each line has a semi colon after each identifier
if line[2:3] != ";":
print "\nThere is a problem with the identifier on line", x + 1
print line
Pete
Comment