On Fri, Oct 5, 2012 at 2:54 AM, Steven D'Aprano <st...@pearwood.info> wrote:
>
> py> from __future__ import division
> py> from math import ceil
> py> "%*s" % (int(ceil(len(mystring)/8)*8), mystring)
> '    123412341234'
>
>
> Or left-justified:
>
> py> "%-*s" % (int(ceil(len(mystring)/8)*8), mystring)
> '123412341234    '

Or use floor division with -n:

    >>> lenstep = lambda s, n: -n * (len(s) // -n)

    >>> mystring = '123412341234'
    >>> "{1:<{0}s}".format(lenstep(mystring, 8), mystring)
    '123412341234    '
    >>> "{1:>{0}s}".format(lenstep(mystring, 8), mystring)
    '    123412341234'
    >>> "{1:^{0}s}".format(lenstep(mystring, 8), mystring)
    '  123412341234  '
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to