How can I format the string according to its length at runtime?
Bjorn Pettersen
BPettersen at NAREX.com
Tue Jun 19 18:11:08 EDT 2001
> From: ed_tsang at yahoo.com [mailto:ed_tsang at yahoo.com]
>
> 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.
Use the * specifier
>>> s = 123
>>> '(0x%-*d)' % (6, s)
'(0x123 )'
>>>
-- bjorn
More information about the Python-list
mailing list