I am currently looking to build a script that takes .txt files (tab delimited) and converts them to .csv. I am getting and error that says (a bytes-like object is required, not 'str') when running the following code. What is the best way to complete this operation?
import csv
import itertools
txt_file_P_T = r"mytxt_P_T.txt"
txt_file_P_C = r"mytxt_P_C.txt"
txt_file_S_T = r"mytxt_S_T.txt"
txt_file_S_C = r"mytxt_S_C.txt"
csv_file_P_T = r"mycsv_P_T.csv"
csv_file_P_C = r"mycsv_P_C.csv"
csv_file_S_T = r"mycsv_S_T.csv"
csv_file_S_C = r"mycsv_S_C.csv"
text_list = [txt_file_P_T, txt_file_P_C, txt_file_S_T, txt_file_S_C]
csv_list = [csv_file_P_T, csv_file_P_C, csv_file_S_T, csv_file_S_C]
for i, j in zip(text_list, csv_list):
in_txt = csv.reader(open(i, "rt"),)
out_csv = csv.writer(open(j, 'wb'))
out_csv.writerows(in_txt)