Handle large output - Python
Question: I am using the python `boto` library to access files in a `S3` bucket. i have
all the output sorted out and works fine. however I dont want to display all
the files on the terminal at once. Say if a person has 800 files and 300
folders in their bucket, displaying all of them at once will be a mess as it
wont be feasible to scroll through all of it. What would be the best way to
display such large output? I was thinking about dividing them into pages but a
little stuck up on the though process. Any help / ideas will be greatly
appreciated

How I iterate over the list

    
    
    for each in file_list:
        print ("{0} ,{1},{2},{3}".format(each.name,each.size,each.version)
    

EDIT:

I append the files into a list and print them out using a `for` loop to
iterate over them and print them using `.format`. A sample looks like this:

    
    
    Files
    file1
    file2
    file3
    file4
    file5
    file6
    file7
    file8
    file9
    file10
    file11
    file12
    file13
    file14
    file15
    file16
    
    Folders:
    
    folder1
    folder2
    folder3
    folder4
    folder5
    folder6
    folder7
    folder8
    


Answer: You can pipe the output to less (inside python using `subprocess`) to get the
`less` command effect on your output.

Sample code:

    
    
    import subprocess
    
    long_array = []
    for i in xrange(1000):
        line = 'Line text number {0}'.format(i)
        long_array.append(line)
    output_string = '\n'.join(long_array)  # can be anything you want as long as it is a string
    
    proc = subprocess.Popen('less', stdin=subprocess.PIPE)
    proc.communicate(output_string)
    

