Jeff Abrahamson on 8 Oct 2004 01:20:03 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[PLUG] python string formatting


I want to do something like this:

    for(i = 0; i < 10; i++)
	  printf("%10d", ar[i]);
    printf("\n");

But I want to do it in python.

I could say

    for i in range(len(ar)):
        print "%10d" % ar[i]

or even

    for d in ar:
        print "%10d" % d

But neither prints to a single line.

I could build it up as a string and the print, but I don't see how to
format the string properly to get a table with columns.

Any pointers?  Thanks.

-- 
 Jeff

 Jeff Abrahamson  <http://www.purple.com/jeff/>    +1 215/837-2287
 GPG fingerprint: 1A1A BA95 D082 A558 A276  63C6 16BF 8C4C 0D1D AE4B

 A cool book of games, highly worth checking out:
 http://www.amazon.com/exec/obidos/ASIN/1931686963/purple-20

Attachment: signature.asc
Description: Digital signature