If I wanted to close a file in a program with an infinite loop, I could do the following:
file = open('abc', 'w')
while True:
try:
file.write('a\n')
except KeyboardInterrupt:
break
file.close()
But if I just left it like this:
file = open('abc', 'w')
while True:
file.write('a\n')
Would the file not get closed on exit?