使用Python将文件加载到内存中 [英] loading file in memory using Python

查看:669
本文介绍了使用Python将文件加载到内存中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过以下方式将文件加载到内存中:

I try to load a file in memory with this:

import mmap

with open(path+fileinput+'example.txt', 'rb') as f:
       fileinput = mmap.mmap(f.fileno(), 0, prot=mmap.PROT_READ)

运行代码时出现错误:

AttributeError: 'module' object has no attribute 'PROT_READ'

推荐答案

PROT_READPROT_WRITE是Unix特定的.您可能正在寻找:

The PROT_READ and PROT_WRITE are Unix-specific. You're likely looking for:

mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)

mmap页面实际上对于Unix/Windows版本具有不同的条目.

The mmap page actually has different entries for Unix/Windows version.

这篇关于使用Python将文件加载到内存中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆