Jeff Abrahamson on 8 Oct 2004 01:38:02 -0000


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

Re: [PLUG] python string formatting


On Thu, Oct 07, 2004 at 09:19:09PM -0400, Jeff Abrahamson wrote:
>   [33 lines, 112 words, 712 characters]  Top characters: tonraphs
> 
> 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.

Doh: I just need a comma:

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

-- 
 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