Exercise: Context manager


Create a few CSV file likes these:


examples/advanced/a.csv

a11,a12
a21,a22


examples/advanced/b.csv

b13,b14
b23,b24


examples/advanced/c.csv

c15,c16
c25,c26

Merge them horizontally to get this:


examples/advanced/out.csv

a11,a12,b13,b14,c15,c16
a21,a22,b23,b24,c25,c26

  • Do it without your own context manager
  • Create a context manager called myopen that accepts N filenames. It opens the first one to write and the other N-1 to read
with myopen(outfile, infile1, infile2, infile3) as out, ins:
    ...