My question is, what happens to the file object created inside a generator expression after the generator's iterator is exhausted? Has close
been called on it? or this benefit only comes while reading file using with
statement?
Example
my_file = (nth_row for nth_row in open(file_path, "rt"))
while True:
try:
print(next(my_file))
except StopIteration:
print("End of the file")
break