-1

i have a list of data like

Name\n Designations Mobile Email Adiba Chairman +880123456 [email protected] delim Asst Prof +8801734534 [email protected] mali Asst Prof +88013254534 [email protected]

now i want to put this in csv file like this farmat.

Name    Designations    Mobile             Email
Adiba   Chairman        +880123456      [email protected]
delim   Asst Prof       +880173453      [email protected]
mali    Asst Prof       +88013254534    [email protected]

how can i separate 4 part using python language?

RH Likhon
  • 29
  • 2

1 Answers1

0

So, you have a list of lists/tuples where in each tuples there are 4 parts - Name, Designation, Phone and Email. So, you can simply do this -

csvfile =  open("hello.csv", "w", newline="")
writer = csv.writer(csvfile)
writer.writerows(list_to_write)
csvfile.close()

Make sure you close the file when you are done.

EDIT

If you are scrapping from a webpage then after getting the values of Name, Designation, Phone and Email make a tuple and then append it to the list.

list_to_write = []
append_it = (Name, Designation, Phone, Email)
list_to_write.append(append_it)

While writing to csv file be careful about csv.writerow(). Use csv.writerows(), it will write all the rows you have in your list and csv.writerow() will write only the 1st row.

MD. Khairul Basar
  • 4,976
  • 14
  • 41
  • 59