Python Script : Convert txt file to csv file

Dear Friends,

Some times you need to convert txt file to csv file automatically. Below is the code:

import csv

text1 = r"textfile.txt"
csv1 = r"csvfile.csv"

inputtxt = csv.reader(open(text1, "rb"), delimiter = '\t')
outputcsv = csv.writer(open(csv1, 'wb'))

outputcsv.writerows(inputtxt)


++++++++++++++++++++++++++++++++++++++++++

Note : csv package is available in python by default. 




Comments