So I want to convert a simple tab delimited text file into a csv file. If I convert the txt file into a string using string.split('
') I get a list with each list item as a string with '' between each column. I was thinking I could just replace the '' with a comma but it won't treat the string within the list like string and allow me to use string.replace. Here is start of my code that still needs a way to parse the tab "".
import csv
import sys
txt_file = r"mytxt.txt"
csv_file = r"mycsv.csv"
in_txt = open(txt_file, "r")
out_csv = csv.writer(open(csv_file, 'wb'))
file_string = in_txt.read()
file_list = file_string.split('
')
for row in ec_file_list:
out_csv.writerow(row)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…