[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Print formatting

On 10/18/19 2:21 PM, Jagga Soorma wrote:
> I seem to have found a way to do this with the following:
>   print('{:<12s}{:>12s}'.format((temp_list[0]),(temp_list[3])))
> Still let me know if there is a better way to format this output :)

I would start with removing the redundant parens.


But then I would simplify it further.


You can do a similar thing with dictionaries.


You can even mix and match.

print('{0[0]:<12s}{1[data3]:>12s}'.format(temp_list, temp_dict))

Finally, if this is in a loop do this.

FMT = '{0[0]:<12s}{0[3]:>12s}'.format
for temp_list in GetLists(): print FMT(temp_list)


D'Arcy J.M. Cain
Vybe Networks Inc.
IM:darcy at Vex.Net VoIP: sip:darcy at