I have this format that I need to comply with in other to print a list of number (the list has over 200 numbers):
my_format = '%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d\n'
my_list = [1,2,3,4,5,6,199, 57, .........]
Basically, it is just %6d repeated 15 times.
When you use % to format a string, I know you need to do this:
with open('my_out.txt', 'w') as fout:
fout.write(my_format % (num1, num2, num3, num4, num5, ....., num15)
In my case I would need to split my_list into 15 pieces and in the last piece, I may not have 15 numbers; therefore, I would need to somehow ignore the variables num that just have no item from my_list because I already iterated through all the numbers. Also, considering that I would need to create 15 variables (from num1 to num15), so I can use:
my_format % (num1, num2, num3, num4, num5, ....., num15)
My file should look like this:
0 1 2 3 4 5 6 7 8 9 1 1 2 1 1
1 4 5 8 9 7 5 8 9 7 6 5 4 3 0
3 4 6 7 1 8
Is there a smart and efficient way that I can solve my problem?