You need to separate the "output" part of the code so that it runs once for each iteration of the for in_file
loop:
import csv import os import glob directory = raw_input ("INPUT Folder") output = raw_input("OUTPUT Folder:") in_files = os.path.join(directory, '*.csv') for in_file in glob.glob(in_files): with open(in_file) as input_file: reader = csv.reader(input_file) cols = [] for row in reader: cols.append(row)
In your version, this code is run only once, after the for in_file
loop has completed and, therefore, only displays cols
data remaining after the last iteration of this loop.
I also "exceeded" the filename = ...
statement at the for in_file
level, since this needs to be done only once for each in_file
, and not once for each row
for each in_file
.
source share