cpython: c226133b1493 (original) (raw)
Mercurial > cpython
changeset 82637:c226133b1493 2.7
#17402: avoid shadowing built-in map in mmap examples. Initial patch by Aman Shah. [#17402]
Ezio Melotti ezio.melotti@gmail.com | |
---|---|
date | Wed, 13 Mar 2013 02:26:11 +0200 |
parents | 4a5ad099b176 |
children | 4edde40afee6 |
files | Doc/library/mmap.rst |
diffstat | 1 files changed, 12 insertions(+), 12 deletions(-)[+] [-] Doc/library/mmap.rst 24 |
line wrap: on
line diff
--- a/Doc/library/mmap.rst +++ b/Doc/library/mmap.rst @@ -114,19 +114,19 @@ memory but does not update the underlyin with open("hello.txt", "r+b") as f: # memory-map the file, size 0 means whole file
map = mmap.mmap(f.fileno(), 0)[](#l1.7)
mm = mmap.mmap(f.fileno(), 0)[](#l1.8) # read content via standard file methods[](#l1.9)
print map.readline() # prints "Hello Python!"[](#l1.10)
print mm.readline() # prints "Hello Python!"[](#l1.11) # read content via slice notation[](#l1.12)
print map[:5] # prints "Hello"[](#l1.13)
print mm[:5] # prints "Hello"[](#l1.14) # update content using slice notation;[](#l1.15) # note that new content must have same size[](#l1.16)
map[6:] = " world!\n"[](#l1.17)
mm[6:] = " world!\n"[](#l1.18) # ... and read again using standard file methods[](#l1.19)
map.seek(0)[](#l1.20)
print map.readline() # prints "Hello world!"[](#l1.21)
mm.seek(0)[](#l1.22)
print mm.readline() # prints "Hello world!"[](#l1.23) # close the map[](#l1.24)
map.close()[](#l1.25)
mm.close()[](#l1.26)
The next example demonstrates how to create an anonymous map and exchange @@ -135,16 +135,16 @@ memory but does not update the underlyin import mmap import os
map = mmap.mmap(-1, 13)[](#l1.34)
map.write("Hello world!")[](#l1.35)
mm = mmap.mmap(-1, 13)[](#l1.36)
mm.write("Hello world!")[](#l1.37)
pid = os.fork() if pid == 0: # In a child process
map.seek(0)[](#l1.42)
print map.readline()[](#l1.43)
mm.seek(0)[](#l1.44)
print mm.readline()[](#l1.45)
map.close()[](#l1.47)
mm.close()[](#l1.48)