Maybe this analogy will help.
A file is a book.
You open a book -- In programming, this will create some reference variable in memory to point to the "front page" in read/write mode, or "last page" in append mode.
While the "book" is open, you can "read" it and "flip through the pages" -- In Python, this is done by open
then read
, readlines
, seek
, etc.
The "book" remains opened, then it takes up some space where it is opened. -- In programming, this is general Operating System memory. Think of this like space on your desk.
When you "close the book", then the space it occupies is freed. Think about this like taking the book off your desk and placing it back on a shelf, out of the way.
Closing again isn't possible because it is already closed.
Not closing the "book" and opening more "books" causes you to run out of space because you can only place so many books on the desk -- In programming, this would be comparable to a resource leak.