import sys import os raw_dir = '../CSV_files_raw/' fixed_dir = '../CSV_fixed' if not os.path.exists(fixed_dir): os.mkdir(fixed_dir) f_dict = {os.path.basename(f):[os.path.join(raw_dir, f), os.path.join(fixed_dir, f)] for f in os.listdir(raw_dir) if f.endswith('.csv')} for f in f_dict.keys(): with open(f_dict[f][0], 'r') as raw, open(f_dict[f][1], 'w') as fixed: for line in raw: line = line.strip().split('\t') fixed.write(','.join(line) + '\n')