The mmap Module
The mmap module supplies memory-mapped file objects. An mmap object behaves similarly to a plain (not Unicode) string, so you can often pass an mmap object where a plain string is expected. However, there are differences:
An
mmapobject does not supply the methods of a string object.An
mmapobject is mutable, while string objects are immutable.An
mmapobject also corresponds to an open file and behaves polymorphically to a Python file object (as covered in File-Like Objects and Polymorphism).
An mmap object m can be indexed or sliced, yielding plain strings. Since m is mutable, you can also assign to an indexing or slicing of m. However, when you assign to a slice of m, the righthand side of the assignment statement must be a string of exactly the same length as the slice you’re assigning to. Therefore, many of the useful tricks available with list slice assignment (covered in Modifying a list) do not apply to mmap slice assignment.
Module mmap supplies a factory function that is slightly different on Unix-like systems and Windows.
mmap |
Creates and returns an |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access