[Tutor] Need to be taught a trick or two about printing in neat columns

Kent Johnson kent37 at tds.net
Thu Nov 2 21:35:12 CET 2006


Dick Moores wrote:
> At 11:33 AM 11/2/2006, Markus Rosenstihl wrote:
>> Try somthing like this:
>>
>> In [32]: a=range(100)
>> In [33]: for i in range(0,len(a)):
>>     ....:     print '%-27s'%a[i],
>>     ....:     if (i+1)%3 == 0: print "\n"
>>
>> 0                           1                           2
>>
>> 3                           4                           5
>> ...
>> 93                          94                          95
>>
>> 96                          97                          98
>>
>> 99
>>
>>
>> Note the comma after the first print statement
> 
> Yes, thanks, but the reason I wanted 3 columns was to compress the 
> height of the list printout for the user, so I don't want all those 
> blank lines.

Just change 'print "\n"' to 'print'

Kent



More information about the Tutor mailing list