write a function that reads a csv file and creates another csv file with same content but with different delimiter
Answers
Explanation:
Reading CSV Files With csv Reading from a CSV file is done using the reader object. The CSV file is opened as a text file with Python's built-in open() function, which returns a file object. This is then passed to the reader , which does the heavy lifting.
Answer:
import csv
def func():
f = open(input("Enter the file to copy from:"),'r')
a = input("Enter a filename to copy to:")
fc = open(a,'w')
w = csv.writer(fc,delimiter='|')
lst = []
d = csv.reader(f)
for r in d:
lst.append(r)
f.close()
w.writerows(lst)
fc.close()
with open(a) as f:
d = csv.reader(f)
for r in d:
print(r)
func()
Explanation:
when prompted to give file name also write the respective extension like .csv