18

Does Python interpreter load all the file to RAM when it is opened for writing?

with open('file.txt' 'w') as file:
    file.write(some_content)
1
  • 1
    Opening in w mode truncates the file anyway, so there are no contents to load into memory. Also noteworthy: open takes a third, optional argument, which lets you control buffer size when reading. Commented Feb 16, 2015 at 9:46

1 Answer 1

29

No. As per the docs, open() wraps a system call and returns a file object, the file contents are not loaded into RAM (unless you invoke, E.G., readlines()).

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.