def ContentGenerator(csv_file, batch_size, create_csv_reader=csv.reader, create_csv_writer=csv.writer):
 try:
  csv.field_size_limit(800000)
 except AttributeError:
  pass
 reader = create_csv_reader(csv_file, skipinitialspace=True)
 exhausted = False
 while (not exhausted):
  rows_written = 0
  content = StringIO.StringIO()
  writer = create_csv_writer(content)
  try:
   for i in xrange(batch_size):
    row = reader.next()
    writer.writerow(row)
    rows_written += 1
  except StopIteration:
   exhausted = True
  if (rows_written > 0):
   (yield (rows_written, content.getvalue()))

def ContentGenerator ( csv_file , batch_size , create_csv_reader = csv . reader , create_csv_writer = csv . writer ) : try : csv . field_size_limit ( 800000 ) except AttributeError : pass reader = create_csv_reader ( csv_file , skipinitialspace = True ) exhausted = False while ( not exhausted ) : rows_written = 0 content = StringIO . StringIO ( ) writer = create_csv_writer ( content ) try : for i in xrange ( batch_size ) : row = reader . next ( ) writer . writerow ( row ) rows_written += 1 except StopIteration : exhausted = True if ( rows_written > 0 ) : ( yield ( rows_written , content . getvalue ( ) ) )
retrieves csv data up to a batch size at a time .