Lazy Method for Reading Big File in Python?


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  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)

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.