Created
October 24, 2013 09:28
-
-
Save alexanderlz/7134006 to your computer and use it in GitHub Desktop.
Get lines from file by separator other than '\n' - under the restriction that it should be the beginning of line
for example - in file: [1]abcderf
[2] this is some
split line
with newlines in it
[3] the third one the method should yield only 3 lines if the "line" marker is '['
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fetchLinesByMarker(ffile, lineMarker): | |
buff = [] | |
for ln in ffile: | |
if ln.startswith(lineMarker): | |
if buff: | |
yield(''.join(buff)) | |
del(buff[:]) | |
buff.append(ln) | |
yield(''.join(buff)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment