On 04/21/12 14:44, Roy Smith wrote: > print "* %-*s *" % (max_length, data)
On Apr 21, 2012, at 4:12 PM, Tim Chase wrote: > Sounds like a lot more work and less flexible than using the (underemployed) > .ljust() or .center() methods of a string. :-) > > print "* %s *" % data.ljust(42) Six of one, half dozen of the other. As I understand the problem, the width of the star-box is supposed to float to just enclose the longest line of data. So, you still need to iterate over the lines to figure out which one is longest. Once you've got that, it's the difference between: > "* %-*s *" % (max_length, data) > "* %s *" % data.ljust(max_length) Use whichever one feels more natural to you. I grew up with printf(), so I learned my way around all wonderful format specifiers. If you don't come from that background, I guess I can see why it might all look like gibberish and ljust() comes to mind first. -- Roy Smith r...@panix.com -- http://mail.python.org/mailman/listinfo/python-list