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.
    – Carsten
    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()).

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.