Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #
  3. # Copyright 2007 Doug Hellmann.
  4. #
  5. """Reading from a memory mapped file.
  6.  
  7. """
  8.  
  9. #end_pymotw_header
  10.  
  11. import mmap
  12. import contextlib
  13.  
  14. with open('lorem.txt', 'r') as f:
  15. with contextlib.closing(mmap.mmap(f.fileno(), 0,
  16. access=mmap.ACCESS_READ)
  17. ) as m:
  18. print 'First 10 bytes via read :', m.read(10)
  19. print 'First 10 bytes via slice:', m[:10]
  20. print '2nd 10 bytes via read :', m.read(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement