I have a file containing some lines of code followed by a string pattern. I need to write everything before the line containing the string pattern in file one and everything after the string pattern in file two:
e.g. (file-content)
- codeline 1
- codeline 2
- string pattern
- codeline 3
The output should be file one with codeline 1, codeline 2 and file two with codeline 3.
I am familiar with writing files, but unfortunately I do not know how to determine the content before and after the string pattern.
If the input file fits into memory, the easiest solution is to use
str.partition():This assumes that you know the exact text of the line separating the two parts.