I have been having a bit of trouble looking up a good explanation on how to do this so pointing me to the right direction would be helpful for the following problem.
I need to have a header printed out in a pretty format along with data, unfortunately what happened is shown below.
DeviceName KB used KB quota KB hard limit grace
/media/Stuff 58384 5242880 0 none
In order to do this I built a list for the header.
HEADER=['DeviceName', 'KB USED', . . .]
and the same thing with the other entries that I need to print out. In order to print it out the above I did something like this
print "".join('%s'.rjust(5) %i for i in HEADER)
So this obviously does not work because the rjust just pads spaces to the right of string. Is there a way to print a string such that it takes up exactly a certain width and if the string isn't long enough to fit the width, then just pad it with spaces?
P.S. I am limited to python 2.4 which means I can't use format from python 2.7.
rjust()on the string after the fact.str(i).rjust(5)or as has been pointed out"%5s" % i