Loading a file into memory using Python

I am trying to load a file into memory using 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 is:

 AttributeError: 'module' object has no attribute 'PROT_READ' 
+4
source share
2 answers

PROT_READ and PROT_WRITE are Unix specific. You are most likely looking for:

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

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

+9
source

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

+1
source

Source: https://habr.com/ru/post/1447578/


All Articles