Created
March 26, 2020 04:32
-
-
Save yadudoc/287404668c2371a0779aeac841fa547a to your computer and use it in GitHub Desktop.
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 generate_batch(filename, start=0, batchsize=10, max_batches=10): | |
| counter = 0 | |
| if max_batches == 0: | |
| max_batches = 999999999 | |
| with open(filename) as current: | |
| while current and counter < max_batches: | |
| yield current.tell() | |
| counter += 1 | |
| for i in range(batchsize): | |
| x = current.readline() | |
| if not x: | |
| current = None | |
| break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment