Oct-01-2020, 02:09 AM
So I have the following text file named test.txt containing the following lines:
This is line 1.
This is line 2.
This is line 3.
The following code is used to parse the file:
['This is line 2.\n']
How do I lose the \n. part in the output?
This is line 1.
This is line 2.
This is line 3.
The following code is used to parse the file:
testfile = open(r"C:\Users\Mohammad\Documents\test.txt") result = [line for line in testfile if "2" in line] print(result)Output:
['This is line 2.\n']
How do I lose the \n. part in the output?