I'm new to python and programming in general and wonder if anyone would be able to help me...
I am trying to open a text file, search for a certain value (1585 in this case), and then write all of the lines containing this value to a new text file.
I have encosed the code I have been trying to write but this just seems to write each line to the text file, which is then overwritten by the next line. Do you have any ideas? Any help would be greatly appreciated!
a = open(r'F:\tester.txt').xreadlines() for line in a: if (line.find('1585')!=-1): isolated_lines = line file = open('F:\write_it.txt', 'w') file.write(str(isolated_lines)) file.close