Buy DarkLaunch.com

Dark Launch

Python open multiple files

Open multiple files in python using file context managers.

Python
import csv
 
 
with open('in.csv', 'r') as fr, open('out.csv', 'w') as fw:
    reader = csv.reader(fr)
    writer = csv.writer(fw)
 
    for i, row in enumerate(reader):
        row.insert(0, i)
        writer.writerow(row)