7

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
  • How are you testing how many lines it gives? Commented Nov 21, 2012 at 21:27

2 Answers 2

13

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.

Sign up to request clarification or add additional context in comments.

Comments

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'.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.