I'm having some problems getting a file to memory map, and was hoping to resolve this issue. I've detailed the problem and shown my code below.
What I'm importing:
import os
import mmap
Now, for the code:
file = r'otest' # our file name
if os.path.isfile(file): # test to see if the file exists
os.remove(file) # if it does, delete it
f = open(file, 'wb') # Creates our empty file to write to
print(os.getcwd())
Here is where I encounter the problem with my code (I've included both, and have one commented out each time I run the program):
mfile = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_WRITE)
#mfile = mmap.mmap(f.fileno(), 10**7, access=mmap.ACCESS_WRITE)
I'm encountering an error with either of the mfile lines.
For the mmap.mmap
line with the 0
argument I get this error: ValueError: cannot mmap an empty file
. If I instead use the 10**7
argument I get this error instead: PermissionError: [WinError 5] Access is denied
And to end it:
"""
Other stuff goes here
"""
f.close() # close out the file
The 'other stuff here' is just a place holder for a where I'm going to put more code to do things.
Just to add, I've found this thread which I thought may help, but both the ftruncate
and os.truncate
functions did not seem to help the issue at hand.