I have a function like:
def func(filename):
with open(filename) as f:
return [line.split('\t')[0] for line in f]
Is the "with" statement closing the file even when there is a 'sudden' function return? Can I ignore the "with" statement? i.e. is it safe and equivalent (from a memory leak perspective) to do,
def func(filename):
return [line.split('\t')[0] for line in open(filename)]
?