Python | delimited text file to csv format
<p>I'm new to python but I'm having trouble reading a text file which contains data separated by "|" as the delimiter. How would I separate the file into columns in a CSV format.</p>

<pre><code>import csv
my_file_name = "NVG.txt"
cleaned_file = "cleanNVG.csv"

with open(my_file_name, 'r') as infile, open(cleaned_file, 'w') as outfile:
    data = infile.read()

    data = data.replace("|","")
    outfile.write(data)
</code></pre>

<p>This code gets rid of the <strong>|</strong> to a blank but all the data is just in one column now. How can I format this correctly?
I appreciate your help in advance.</p>

<p>The simplest way with your code would be to replace "|" with "," rather than removing "|"<br /></p>

<pre><code>data = data.replace("|", ",")
</code></pre>

python python-3.x