I am reading some data from a .txt file in Python using the following:
fileData = open("file.txt", "rb").read()
I know that you should always close opened files, and I assume in this case the file remains open. Is there a way to close the file without assigning it to a variable?
I'd like to avoid:
openedFile = open("file.txt", "rb")
fileData = openedFile.read()
openedFile.close()
And also:
with open("file.txt", "rb") as openedFile:
fileData = openedFile.read()
It might not be possible, in which case okay, but just making sure.