In Python, while reading the file’s content, it is recommended to use the with
block.
Something like below
with open(file, 'r', encoding='utf-8') as f:
content = f.read().splitlines()
However, if I am not processing much, I can do something like below in one line, which looks more compact.
content = open(file, 'r', encoding='utf-8').read().splitlines()
Is there any advantage of one over another? Say in terms of garbage collection etc.?