A
A
AleksRT2014-04-11 13:39:29
Python
AleksRT, 2014-04-11 13:39:29

python generator?

How to use a generator in python to merge files?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valentine, 2014-04-11
@AleksRT

def test(f1, f2):
    with open(f1, 'r') as fd:
        for i in fd.xreadlines():
            yield i
    with open(f2, 'r') as fd:
        for i in fd.xreadlines():
            yield i

for i in test("file1", "file2"):
   print i

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question