Printing Lists as Tabular Data

后端 未结 14 2097
小蘑菇
小蘑菇 2020-11-21 06:38

I am quite new to Python and I am now struggling with formatting my data nicely for printed output.

I have one list that is used for two headings, and a matrix that

14条回答
  •  無奈伤痛
    2020-11-21 07:15

    I think this is what you are looking for.

    It's a simple module that just computes the maximum required width for the table entries and then just uses rjust and ljust to do a pretty print of the data.

    If you want your left heading right aligned just change this call:

     print >> out, row[0].ljust(col_paddings[0] + 1),
    

    From line 53 with:

     print >> out, row[0].rjust(col_paddings[0] + 1),
    

提交回复
热议问题