Created
November 11, 2014 04:20
-
-
Save tianweidut/ab9fa6643b12f7c1366b to your computer and use it in GitHub Desktop.
mmap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding: utf-8 | |
import sys | |
import os | |
import mmap | |
def get_mmap(filepath): | |
with open(filepath, 'r+b') as f: | |
mm = mmap.mmap(f.fileno(), 0) | |
return mm | |
def test(path): | |
mm = get_mmap(path) | |
a = raw_input('input:') | |
print mm.readline() | |
mm[:3] = 'new' | |
mm.seek(0) | |
print mm.readline() | |
a = raw_input('input:') | |
mm.close() | |
if __name__ == "__main__": | |
path='/tmp/test_mmap.txt' | |
with open(path, 'w') as f: | |
f.writelines('test test.....') | |
test(path) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding: utf-8 | |
import sys | |
import os | |
import mmap | |
def get_mmap(filepath): | |
with open(filepath, 'r+b') as f: | |
mm = mmap.mmap(f.fileno(), 0) | |
return mm | |
def test(path): | |
mm = get_mmap(path) | |
print mm.readline() | |
a = raw_input('wait1:') | |
mm.seek(0) | |
print mm.readline() | |
mm.close() | |
if __name__ == "__main__": | |
path='/tmp/test_mmap.txt' | |
test(path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment