How can I format the string according to its length at runtime?
Remco Gerlich
scarblac at pino.selwerd.nl
Wed Jun 20 03:04:25 EDT 2001
ed_tsang at yahoo.com <ed_tsang at yahoo.com> wrote in comp.lang.python:
> I am trying to supply the precision formating at run time:
>
> s = 123
> print '(0x%-6X -)'%s
>
> where I try to dynamically supply the number 6 from (6- length of s),
> I can't find a way to dynamically supply that.
>
> Anyone hav any idea?
s = 123
spacing = 6
print '(0x%*X -)' % (spacing, s)
Ie, use '*'.
--
Remco Gerlich
More information about the Python-list
mailing list