Filesystem and I/O Modules
mmap
Creates memory mappings that support byte access and file-like seeking. ACCESS_READ prevents writes; ACCESS_COPY permits private changes without updating the file. ACCESS_WRITE changes shared file storage. Mapping constraints depend on OS and file size; flush buffered writes before mapping and close mappings before closing the file.
Formal Syntax & Structure
python syntaxpython
import mmapReturn Value
module
Module namespace available through import; import is a statement, not a value-returning expression.
Working Example
Example Snippetpython
import mmapfrom tempfile import TemporaryFilewith TemporaryFile() as file: file.write(b"hello") file.flush() with mmap.mmap(file.fileno(), 0, access=mmap.ACCESS_READ) as view: print(view[1:4])