newbie question concerning formatted output

Scott David Daniels scott.daniels at acm.org
Tue Nov 29 21:27:57 EST 2005


Thomas Liesner wrote:
> ... i want to print always three of them in a single line and 
 > after that a linebreak.

How about:

     def emit(aFile):
         for line in aFile:
             for word in line.split():
                 yield word

     f = open('xyplan.nobreaks', 'r')
     gen = iter(emit(f)).next
     try:
         while True:
             for i in range(2):
                 print gen(),
             print gen()
     except StopIteration:
         pass
     f.close()
     print

--Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list