Q. Write a function that reads a csv file and creates another csv file with the same content, but with a different delimiter.


Answer :-

import csv

def Pathwalla( file1 ):
    file2 = open( "Portalexpress.csv","w",newline="" )
    portal_write = csv.writer( file2 , delimiter = "|")

    data = csv.reader(file1)

    for i in data :
        if i[0][:5] != "check" :
            portal_write.writerow( i )
    file2.close()

file1 = open( "Pathwalla.csv","r" )
Pathwalla( file1 )
print ("Thank You !!")

Content in Pathwalla.csv :-

This is Path Wall Website.
check here you find all solution
Tell me about you
check are you fine
Ok thankyou

Output :-

Thank You !!
>>> 

Content in Portalexpress.csv after program running:-

This is Path Wall Website.
Tell me about you
Ok thankyou


9 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. but thats not the csv file you have done in txt file? why so?

    ReplyDelete
    Replies
    1. Please go carefully with code whole program have written for csv file.

      Delete
  2. You are done in a csv file but you are saved in a txt file.why??

    ReplyDelete
  3. different question different answer.......

    ReplyDelete
  4. The question is different and the answer is different too. This answer is for the question after this one

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post