How can I format the string according to its length at runtime?
skip at pobox.com
Tue Jun 19 18:16:24 EDT 2001
ed> I am trying to supply the precision formating at run time:
ed> s = 123
ed> print '(0x%-6X -)'%s
ed> where I try to dynamically supply the number 6 from (6- length of s),
ed> I can't find a way to dynamically supply that.
Basically, you put * where you want to interpolate the width from a number:
>>> wid = 12
>>> print '(0x%*s)' % (wid, "allan")
Skip Montanaro (skip at pobox.com)
More information about the Python-list