質問

この単純な関数を使用しています:

def print_players(players):
    tot = 1
    for p in players:
        print '%2d: %15s \t (%d|%d) \t was: %s' % (tot, p['nick'], p['x'], p['y'], p['oldnick'])
        tot += 1

また、ニックネームは15文字以下であると思われます。
各「列」を保持したい整列された、同じことを可能にする構文糖衣がありますが、ニックネーム列を右揃えではなく左揃えにし、右側の列を壊すことはありませんか?

同等のいコードは次のようになります。

def print_players(players):
    tot = 1
    for p in players:
        print '%2d: %s \t (%d|%d) \t was: %s' % (tot, p['nick']+' '*(15-len(p['nick'])), p['x'], p['y'], p['oldnick'])
        tot += 1

すべてのおかげで、ここに最終版があります:

def print_players(players):
    for tot, p in enumerate(players, start=1):
        print '%2d:'%tot, '%(nick)-12s (%(x)d|%(y)d) \t was %(oldnick)s'%p
役に立ちましたか?

解決

p が辞書のように見えるのを見て、どうですか:

print '%2d' % tot + ': %(nick)-15s \t (%(x)d|%(y)d) \t was: %(oldnick)15s' % p
scroll top