title: Python TypeError: expected str, bytes or os.PathLike object, not _io.TextIOWrapper
body: <p>I am trying to convert a pipe-delimited text file to a CSV file, and then iterate through and print the CSV file. Here is my code:</p>
  
  <pre><code>
  with open("...somefile.txt", "r") as text_file:
      text_reader = csv.reader(text_file, delimiter='|')
      with open("...somefile.csv", 'w') as csv_file:
          csv_writer = csv.writer(csv_file, delimiter=',')
          csv_writer.writerows(text_reader)
  
  with open (csv_file, 'r') as f:
      reader = csv.reader (f, delimiter=',')
      for row in reader:
          print(row)
  </code></pre>
  
  <p>However, I am getting this error message :</p>
  
  <pre><code>----&gt; 9 with open (csv_file, 'r') as f:
       10     reader = csv.reader (f, delimiter=',')
       11     for row in reader:
  
  TypeError: expected str, bytes or os.PathLike object, not _io.TextIOWrapper
  </code></pre>
  
  <p>Can anyone explain what this means?</p>
  
  <p>Also, if I were to make this into a function, how could I take in a file name as input and then change the file to add a .csv extension wen converting to a csv file?</p>
  
  <p>Thanks</p>