how to skip blank line while reading CSV file using python

后端 未结 8 619
终归单人心
终归单人心 2020-12-03 20:55

This is my code i am able to print each line but when blank line appears it prints ; because of CSV file format, so i want to skip when blank line appears

im         


        
8条回答
  •  执笔经年
    2020-12-03 21:30

    my suggestion would be to just use the csv reader who can delimite the file into rows. Like this you can just check whether the row is empty and if so just continue.

    import csv
    
    with open('some.csv', 'r') as csvfile:
    
        # the delimiter depends on how your CSV seperates values
        csvReader = csv.reader(csvfile, delimiter = '\t')
    
        for row in csvReader:
            # check if row is empty
            if not (row):    
                continue
    

提交回复
热议问题