15

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)
I159
  • 29,741
  • 31
  • 97
  • 132
  • 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 Feb 16 '15 at 09:46

1 Answers1

25

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

Mark R.
  • 1,273
  • 8
  • 14