def format_to_csv(filename, skiprows=<NUM_LIT:0>, delimiter="<STR_LIT>"):
if not delimiter:<EOL><INDENT>delimiter = "<STR_LIT:\t>"<EOL><DEDENT>input_file = open(filename, "<STR_LIT:r>")<EOL>if skiprows:<EOL><INDENT>[input_file.readline() for _ in range(skiprows)]<EOL><DEDENT>new_filename = os.path.splitext(filename)[<NUM_LIT:0>] + "<STR_LIT>"<EOL>output_file = open(new_filename, "<STR_LIT:w>")<EOL>header = input_file.readline().split()<EOL>reader = csv.DictReader(input_file, fieldnames=header, delimiter=delimiter)<EOL>writer = csv.DictWriter(output_file, fieldnames=header, delimiter="<STR_LIT:U+002C>")<EOL>writer.writerow(dict((x, x) for x in header))<EOL>for line in reader:<EOL><INDENT>if None in line: del line[None]<EOL>writer.writerow(line)<EOL><DEDENT>input_file.close()<EOL>output_file.close()<EOL>print("<STR_LIT>" % new_filename)<EOL>
Convert a file to a .csv file