I am aware that when you open a file in Python, you must always close it. However, I was wondering what happens if you're not assigning your file to a variable and are only opening it in a print function.
Example: print(open('file.txt','r').read())
Is there a way to close a file opened within a function?
Something more pythonic than
F=open('file.txt','r')
print(F.read())
F.close()