In my assignment, I was supposed to close a file after reading through it in one function. However, I have to access it again from another function later on. It's a requirement to close the file to enforce a good habit of closing files, but I feel like it's unnecessary as I need to open the file again later. Is there a way to close a file and still access it from another function or should I just reopen it manually.
Example Code:
def open(file):
filename = open(file, "r")
filename.read()
filename.close()
def access():
for line in filename:
print(line)