Skip to content

Instantly share code, notes, and snippets.

@alexanderlz
Created October 24, 2013 09:28
Show Gist options
  • Save alexanderlz/7134006 to your computer and use it in GitHub Desktop.
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 '['
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