1

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

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应该在一列中。

4

1 回答 1

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在上面的示例中)。

于 2013-04-01T07:24:03.133 回答