Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

loading file in memory using Python

Tags:

python

mmap

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'
like image 278
foc Avatar asked Nov 21 '12 19:11

foc


1 Answers

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.

like image 153
cnicutar Avatar answered Nov 15 '22 08:11

cnicutar