Q:

Iterate through parallel lists and convert tab delimited text in one list to csv path in other

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)

A:

The csv module was heavily changed between Python2 and Python3. In Python2, the underlying file object for csv writer should be opened in binary mode. In Python3 it should be opened it text mode (which allows to specify an explicit encoding) and with the newline = '' parameter to avoid any end of line conversion.
So you should have:
...
for i, j   in zip(text_list, csv_list):
      in_txt = csv.reader(open(i))
      out_csv = csv.writer(open(j, 'w', newline = ''))
      out_csv.writerows(in_txt)

