def write_list_to_file(file, L):
    """
    similar to print_list, but writing to given file instead.
    """
    number_per_line = 10
    csv_wanted = True
    for i in range(0, len(L), number_per_line):
        file.write('    ')
        for j in range(min(number_per_line, len(L) - i)):
            file.write('%7d' % L[i + j])
            if csv_wanted:
                file.write(', ')
            else:
                file.write('\t')
        file.write('\n')
