Re: newbie question concerning formatted output



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@xxxxxxx
.



Relevant Pages

  • Re: What makes an iterator an iterator?
    ... Calling a generator, such as this next method, returns an iterator ... calling it repeatedly returns many such iterator objects, ... never raises StopIteration, thus obviously producing an unending loop. ...
    (comp.lang.python)
  • Re: What makes an iterator an iterator?
    ... Calling a generator, such as this next method, returns an iterator ... calling it repeatedly returns many such iterator objects, ... never raises StopIteration, thus obviously producing an unending loop. ...
    (comp.lang.python)