You don't need this, just "for line in fd". This readlines() reads all file into memory, and iterator only iterates through it line by line.