Skip to content

Instantly share code, notes, and snippets.

@yadudoc
Created March 26, 2020 04:32
Show Gist options
  • Select an option

  • Save yadudoc/287404668c2371a0779aeac841fa547a to your computer and use it in GitHub Desktop.

Select an option

Save yadudoc/287404668c2371a0779aeac841fa547a to your computer and use it in GitHub Desktop.
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