Skip to main content
 首页 » 编程设计

Python `open` 函数内存使用

2025年05月04日16fff_TT

Python 解释器在打开写入时是否将所有文件加载到 RAM 中?

with open('file.txt' 'w') as file: 
    file.write(some_content) 

请您参考如下方法:

没有。根据 the docs , open() 包装一个系统调用并返回一个文件对象,文件内容不会加载到 RAM 中(除非你调用,例如 readlines())。