My For loop skips the first line each time I read one line at a time.
The problem doesn’t occur when I just need to read in the entire file into memory, but mostly I need to read in one line a at a time.
Here’s one example where the problem occurs.
This loop just reorders the elements in a list.
I’ve omitted the lines where I open and close read & write files (the clunky way I do it). Its all comma delimited text data.
lineString=fileItemR.readline()
for lineString in fileItemR:
lineList = lineString.split(",")
newList = (lineList[1],lineList[0],lineList[2:99])
lineItem = str(newList)
formatString = lineItem.replace("('","").replace("', '",",").replace("', ",",").replace("['","").replace("\\n","\n").replace("'])","")
fileItemW.write(formatString)
It’s the first
readline()(the one you call before the loop) that eats your first line.