Dynamic construction of a print format string

Fredrik Lundh fredrik at pythonware.com
Wed Mar 14 13:29:23 EST 2001


Bruce Edge wrote:
> I'm using:
>
>   fmtstr = "%s%s%s" % ( "    %", namelen, "s - %s" )
>
> to get:
>
>   "    %19s - %s"

how about:

    format = "    %%%ds - %%s" % namelen
    text = format % (arg1, arg2)

or

    text = "    %*s - %s" % (namelen, arg1, arg2)

Cheers /F





More information about the Python-list mailing list