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


13 Comments

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

  1. The code is wrong. The question says that the new file should contain the same content except the lines starting with "Check". So there should be some sort of an if condition.

    ReplyDelete
  2. We had to make a function(def), please correct it:)

    ReplyDelete
  3. Thanks for this. Helped me alot during my exams.

    ReplyDelete
  4. PLS MAKE IT SMALLER

    ReplyDelete
  5. PLS MAKE IT SMALLER

    ReplyDelete
  6. HI I AM GIRIJA

    ReplyDelete

Post a Comment

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

Previous Post Next Post