Dynamic construction of a print format string

Bruce Edge bedge at troikanetworks.com
Wed Mar 14 18:19:52 EST 2001


Ahh, %*s, the magic trick.

Thanks to all who responded.

-Bruce.


Fredrik Lundh wrote:
> 
> 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