Posted By

laurenceosx on 09/29/09


Tagged

python


Versions (?)

Lazy Method for Reading Big File in Python?


 / Published in: Python
 

URL: http://stackoverflow.com/questions/519633/lazy-method-for-reading-big-file-in-python

  1. f = open('test.zip', 'rb')
  2.  
  3. for data in iter( lambda: f.read(1024) , ''):
  4. pass # do stuff
  5.  
  6. # or without lambda
  7.  
  8. f = open('really_big_file.dat')
  9. def read1k():
  10. return f.read(1024)
  11.  
  12. for piece in iter(read1k, ''):
  13. process_data(piece)

Report this snippet  

You need to login to post a comment.