I think this question is more of a \"coding style\" rather than technical issue.
Said I have a line of code:
buf = open(\'test.txt\',\'r\').readlines
It will stay in memory until the garbage collector closes it. You should always explicitly close your file descriptors. Just do something like this:
with open('test.txt', 'r') as f: buf = f.readlines()