def my_open(filename, char):
    with open(filename) as f:
        old_fb = ''
for file_buffer in iter(lambda : f.read(1024), ''):
    if old_fb:
        file_buffer = old_fb + file_buffer
pos = file_buffer.find(char)
while pos != -1 and file_buffer:
    yield file_buffer[:pos]
file_buffer = file_buffer[pos + 1:]
pos = file_buffer.find(char)
old_fb = file_buffer
yield old_fb
for line in my_open('weirdfile', '~'):
    pass
Прочитать файл до символа