What is the most Pythonic way to interleave text file contents?
<p>Python question:</p>

<p>If I have a list of files, how do I print line #1 from each file, then
line #2, etc.? (I'm a Python newbie, obviously...)</p>

<p>Example:</p>

<pre><code>file1:
foo1
bar1

file2:
foo2
bar2

file3:
foo3
bar3
</code></pre>

<p>Function call:</p>

<pre><code>names = ["file1", "file2", "file3"]
myfct(names)
</code></pre>

<p>Desired output:</p>

<pre><code>foo1
foo2
foo3

bar1
bar2
bar3
</code></pre>

<p>This is how I did it, but I'm sure there is a more elegant, Pythonic way:</p>

<pre><code>def myfct(files):
    file_handlers = []
    for myfile in files:
        file_handlers.append(open(myfile))
    while True:
        done = False
        for handler in file_handlers:
            line = handler.readline()
            eof = len(line) == 0 # wrong
            if (eof):
                done = True
                break
            print(line, end = "")
        print()
        if done == True:
            break
</code></pre>

<p>P.S.: I'm using Python 2.6 with <code>from __future__ import print_function</code>.</p>
