title: Convert a folder of pipe-delimited text files to CSV in Python
body: <p>I have a folder of .txt files which contain "|" instead of commas and I am trying to get it into CSV format. I found some code that will supposedly work, but I keep getting the error "iterator should return strings, not bytes (did you open the file in text mode?)". The code I found was not nested in a <code>for</code> loop, could that be the issue?</p>
  
  <p>The code:</p>
  
  <pre><code>import csv
  import os
  
  folder_path= r'C:\Users\%user%\Documents\data\Dataset'
  txt_files = os.listdir(folder_path)
  
  to_csv = []
  
  for file in range(0, len(txt_files)):
      path_name = os.path.abspath(os.path.join(folder_path, txt_files[file]))
      to_csv.append(path_name)
  
  for file in to_csv:
      with open(file, "rb") as f:
          with_pipes = csv.reader(f, delimiter='|')
          wo_pipes = list(with_pipes)
  </code></pre>