在python中打印漂亮

时间:2013-04-01 07:20:31

标签: python

我想以一种漂亮的方式打印以下几行。

Putting a value ... OK
Getting value with only row key ... OK
Getting value with only row key and family... OK
Getting value with only row key and family and qualifier... OK
Getting value with row key which is not put... OK

我希望所有OK都在一列中。

1 个答案:

答案 0 :(得分:6)

lines = ['Putting a value ...',
         'Getting value with only row key ...',
         'Getting value with only row key and family...',
         'Getting value with only row key and family and qualifier...',
         'Getting value with row key which is not put...']

for line in lines:
  print '%-59s' % line,
  # ...
  print 'OK'

打印

Putting a value ...                                         OK
Getting value with only row key ...                         OK
Getting value with only row key and family...               OK
Getting value with only row key and family and qualifier... OK
Getting value with row key which is not put...              OK

对于这项工作,您需要知道最长字符串的长度(上例中的59)。