loading file in memory using Python

荒凉一梦 提交于 2019-12-22 05:26:12

问题


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)

When I run the code the error:

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

回答1:


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

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

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




回答2:


I recently got the same error message with my test program mmap.py. Renaming my test program to something else (mmap_test.py) fixed the name collision that caused numpy's memmap.py to get when it executed 'import mmap'.



来源:https://stackoverflow.com/questions/13500434/loading-file-in-memory-using-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!