XML : how to remove the blank lines in a csv python

here is my code and im getting 'TypeError: newline is an invalid argument'

i have converted a xml file to csv and now i want the output file to be without blank spaces in between each line.

  import xml.etree.ElementTree as ET  import csv    tree = ET.parse("stores.xml")  root = tree.getroot()    # open a file for writing    stores = open('stores.csv','w', newline='')    # create the csv writer object    csvwriter = csv.writer(stores)  storelocation_head = []    count = 0  for details in root.findall('store'):  store = []  if count == 0:      ID = details.find('ID').tag      storelocation_head.append(ID)      Name = details.find('Name').tag      storelocation_head.append(Name)      postCode = details.find('Postcode').tag      storelocation_head.append(postCode)      State = details.find('State').tag      storelocation_head.append(State)      csvwriter.writerow(storelocation_head)      count = count + 1    ID = details.find('ID').text  store.append(ID)  Name = details.find('Name').text  store.append(Name)  PostCode = details.find('Postcode').text  store.append(PostCode)  State = details.find('State').text  store.append(State)  csvwriter.writerow(store)  stores.close()    

No comments:

Post a Comment