[英]new line as delimiter in CSV file
我想读取一个csv文件,直到找到一个空行/换行,我正在使用END作为分隔符,想将其更改为新行/空行
def getActualData(ws_name, ws_value):
outputDatafile = open('D:\\Files\\Actual_Data.csv', 'r',newline="\n")
outputReader = csv.reader(outputDatafile, delimiter=',', quoting=csv.QUOTE_NONE)
outputData = {}
check =0
for rows in outputReader:
#print "Row first:", rows[0]," Row second:",rows[1]
if(check==0):
if(rows[0]==ws_name and rows[1]==ws_value):
check+=1
elif (rows[0]=='\n' and rows[1]=='\n'):
break
else:
outputData.update({rows[0]:rows[1]})
如果行的长度为0,则表示空行。 您应该先检查空白行。 否则,rows [0]可能会导致异常。
if (len(rows)==0):
break
elif(check==0):
if(rows[0]==ws_name and rows[1]==ws_value):
check+=1
else:
outputData.update({rows[0]:rows[1]})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.