0

When opening and appending to a file in python, does that file get loaded into memory? I'm asking this because I'm writing a program where I write to several files in a round-robin fashion where I have the guarantee that any one file can fit into memory but not all files can fit into memory at the same time. Opening and closing files every time I append is not an option since that would be too slow. As such, I would need all the files opened simultaneously.

1
  • 1
    That depends on what exactly you do. Just open(...) won’t read anything into memory, no. Commented Aug 7, 2020 at 6:50

1 Answer 1

1

The answer is NO. Regarding the documentations of open() wraps a system call and returns a file object (Not the content of file): https://docs.python.org/2/library/functions.html#open

Open a file, returning an object of the file type described in section File Objects.

The file contents are not loaded into RAM unless you read the file with eg.: readlines(), read()

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.