如何删除csv python中的空行

时间:2016-10-19 08:19:34

标签: python xml csv space

这是我的代码,我得到'TypeError:换行是一个无效的参数'

我已将xml文件转换为csv,现在我希望输出文件在每行之间没有空格。

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()

0 个答案:

没有答案