I am trying to write a class that inherits from mmap as follows:
from mmap import mmap
class SBFMap(mmap):
def __init__(self, filename):
f=open(filename, 'rb')
fn = f.fileno()
super().__init__(fn, 0, access = mmap.ACCESS_READ)
As you can guess, part of my class's functionality is to hide the file opening/closing inside my __init__. i then try to get an SBFMap object like so:
from SBFMap import SBFMap
filename = "name\of\file"
mymap = SBFMap(filename)
I get this error:
File "SBFReader.py", line 22 in <module> main()
File "SBFReader.py", line 7, in main mymap=SBFMap(filename)
TypeError: an integer is required (got type str)
Press any key to continue . . .
It appears like instead of python calling SBFMap's __init__ and letting me call mmap's __init__ when I'm ready to, python is trying to call mmap's __init__. How do I fix this?
f=open(filename, 'rb)Please copy/paste also the full stacktrace.__new__instead.SBFMap.__new__. Note thatmmapis implemented in a shared library in C, not pure Python, and it does not actually have an__init__method.__new__.