What I was looking for did not work, so I turn to the experts!
I have text in a tab delimited text file that has some kind of carriage return (when I open it in Notepad ++ and use "show all characters", I see [CR] [LF] at the end of the line). I need to remove this carriage return (or whatever), but I can't figure it out. Here is a fragment of a text file showing a line with a carriage return:
firstcolumn secondcolumn third fourth fifth sixth seventh moreoftheseventh 8th 9th 10th 11th 12th 13th
Here is the code I'm trying to use to replace it, but it does not find a return:
with open(infile, "r") as f: for line in f: if "\n" in line: line = line.replace("\n", " ")
My script just does not find a carriage return. Am I doing something wrong or incorrectly believing that this is a carriage return? I could just delete it manually in a text editor, but the text file contains about 5,000 entries, which may also contain this problem.
Additional information: The goal here is to select two columns from a text file, so I break up the \ t characters and refer to the values โโas part of the array. It works with any line without returns, but fails in the return lines, because, for example, there is no element 9 in these lines.
vals = line.split("\t") print(vals[0] + " " + vals[9])
So, for the line of text above, this code fails because there is no index 9 in this particular array. For lines of text that do not have [CR] [LF], it works as expected.