from cStringIO import StringIO # is this the fastest way to read in $quantity lines from a file? deliverable = StringIO() deliverable.writelines( (data.readline() for i in xrange(quantity)) )