For existing code calling readfp() with arguments which don’t support iteration, the following generator may be used as a wrapper around the file-like object:
readfp(fp, filename=None)
def readline_generator(fp):
line = fp.readline()
while line:
yield line
line = fp.readline()