From my previous post – Python Tutorial 21 : How to read/write a CSV file in Python? – when we read the CSV file, in the end, we have created a very terrible result as follow. Now we are going to rewrite the program and format the print statement.
The following screen captured all lines we have to change
We have removed the nested for loop as it is no longer suitable and replace it with following statement
[vtftable cols=”{0}0:fff2cc;{/}”]
print(‘{0:<26}{1}’.format(p_row[0],p_row[1]));nn;
[/vtftable]
In the slot 0 – {0:<26} – we are allowing 26 spaces and follow by slot 1. Then we use the “.format” function to define the item for each slots.
The left arrow “<” indicated the alignment. We can have following options:
< – Left alignment
^ – center alignment
> – RIght alignment
nothing – simply reserve spaces.