Created
October 5, 2019 01:45
-
-
Save lachlan-eagling/11847f0c40581da7e7e0af2a44516054 to your computer and use it in GitHub Desktop.
Blog - Generators (File Generator)
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
| def read_chunks(filename, mode="r", chunk_size=32): | |
| with open(filename, mode) as f: | |
| while True: | |
| data = f.read(chunk_size) | |
| if not data: | |
| break | |
| yield data | |
| def main(): | |
| filename = "/Users/bob.smith/files/really_really_big.dat" | |
| for chunk in read_chunks(filename): | |
| print(chunk) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment