Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a142a343
Commit
a142a343
authored
Mar 13, 2013
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Plain Diff
#17402: merge with 3.2.
parents
220391fa
67714629
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
14 deletions
+14
-14
Doc/library/mmap.rst
Doc/library/mmap.rst
+14
-14
No files found.
Doc/library/mmap.rst
View file @
a142a343
...
...
@@ -106,19 +106,19 @@ To map anonymous memory, -1 should be passed as the fileno along with the length
with open("hello.txt", "r+b") as f:
# memory-map the file, size 0 means whole file
m
ap
= mmap.mmap(f.fileno(), 0)
m
m
= mmap.mmap(f.fileno(), 0)
# read content via standard file methods
print(m
ap
.readline()) # prints b"Hello Python!\n"
print(m
m
.readline()) # prints b"Hello Python!\n"
# read content via slice notation
print(m
ap
[:5]) # prints b"Hello"
print(m
m
[:5]) # prints b"Hello"
# update content using slice notation;
# note that new content must have same size
m
ap
[6:] = b" world!\n"
m
m
[6:] = b" world!\n"
# ... and read again using standard file methods
m
ap
.seek(0)
print(m
ap
.readline()) # prints b"Hello world!\n"
m
m
.seek(0)
print(m
m
.readline()) # prints b"Hello world!\n"
# close the map
m
ap
.close()
m
m
.close()
:class:`mmap` can also be used as a context manager in a :keyword:`with`
...
...
@@ -126,8 +126,8 @@ To map anonymous memory, -1 should be passed as the fileno along with the length
import mmap
with mmap.mmap(-1, 13) as m
ap
:
m
ap
.write("Hello world!")
with mmap.mmap(-1, 13) as m
m
:
m
m
.write("Hello world!")
.. versionadded:: 3.2
Context manager support.
...
...
@@ -139,16 +139,16 @@ To map anonymous memory, -1 should be passed as the fileno along with the length
import mmap
import os
m
ap
= mmap.mmap(-1, 13)
m
ap
.write(b"Hello world!")
m
m
= mmap.mmap(-1, 13)
m
m
.write(b"Hello world!")
pid = os.fork()
if pid == 0: # In a child process
m
ap
.seek(0)
print(m
ap
.readline())
m
m
.seek(0)
print(m
m
.readline())
m
ap
.close()
m
m
.close()
Memory-mapped file objects support the following methods:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment