Advertisement
rfmonk

mmap_read.py

Jan 28th, 2014
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. import mmap
  2. import contextlib
  3.  
  4. with open('lorem.txt', 'r') as f:
  5.     with contextlib.closing(mmap.mmap(f.fileno(), 0,
  6.                                       access=mmap.ACCESS_READ)
  7.                             ) as m:
  8.         print 'First 10 bytes via read :', m.read(10)
  9.         print 'First 10 bytes via slice:', m[:10]
  10.         print '2nd   10 bytes via read :', m.read(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement