[Tutor] printing columns
Michael P. Reilly
arcege@shore.net
Fri, 21 Jul 2000 08:04:23 -0400 (EDT)
>
> > From: "Richard Chamberlain" <richard_chamberlain@ntlworld.com>
> > Date: Fri, 21 Jul 2000 07:28:15 +0100
> >
> > Hi Ben,
> >
> > Why not use:
> >
> > print "%6s %6s %6s" %(thelist[item1],thelist[item2],thelist[item3])
>
> or, to enhance this story...
>
> i = 1
> while i < 650:
> print "%6s %6s %6s" % (thelist[i], thelist[i+1], thelist[i+2])
> i = i + 3
>
> hope this helps!!
Or even further:
ncols = 3
for i in xrange(0, len(thelist), ncols): # for small ranges, use range()
print ...
Remember that range() and xrange() return first-class objects which can
be passed (or saved in a class instance).
-Arcege
--
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager | Email: arcege@shore.net |
| Salem, Mass. USA 01970 | |
------------------------------------------------------------------------