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()
...
Will the file descriptor automatically close, or will it stay in the memory? If the file descriptor is not closed, what is the prefer way to close it?