This is a carryover from the C formatting markup:
print "%*s, blah" % (max_title_width,column)
If you want left-justified text (for entries shorter than max_title_width
), put a '-' before the '*'.
>>> text = "abcdef"
>>> print "<%*s>" % (len(text)+2,text)
< abcdef>
>>> print "<%-*s>" % (len(text)+2,text)
<abcdef >
>>>
If the len field is shorter than the text string, the string just overflows:
>>> print "<%*s>" % (len(text)-2,text)
<abcdef>
If you want to clip at a maximum length, use the '.' precision field of the format placeholder:
>>> print "<%.*s>" % (len(text)-2,text)
<abcd>
Put them all together this way:
%
- if left justified
* or integer - min width (if '*', insert variable length in data tuple)
.* or .integer - max width (if '*', insert variable length in data tuple)