[Tutor] string formatting and right justifying text

dman dsh8290@rit.edu
Sun, 9 Dec 2001 21:57:42 -0500

On Sun, Dec 09, 2001 at 07:30:14PM -0600, Timothy Wilson wrote:
| Hi everyone,
| I'm working on the next project for my students and I'd like to have them
| print a table of stock prices, number of shares, etc. I can't figure out the
| string formatting codes to right-justify integers or floating point numbers
| so I can make the table look right. Any pointers?

All the format string codes are documented in 'man printf'.  It is
identical to C/C++ string formatting.  To right justify text in a
fixed-width field :

>>> print "%20s" % "yo"
>>> print "%-20s" % "yo"
>>> print "%20d" % 5
>>> print "%-20d" % 5



If any of you lacks wisdom, he should ask God, who gives generously to
all without finding fault, and it will be given to him.  But when he
asks he must believe and not doubt, because he who doubts is like a wave
of the sea, blown and tossed by the wind.
        James 1:5-6