how to skip blank line while reading CSV file using python

后端 未结 8 637
终归单人心
终归单人心 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:45

    This example just prints the data in array form while skipping the empty lines:

    import csv
    
    file = open("data.csv", "r")
    data = csv.reader(file)
    
    for line in data:
        if line: print line
    
    file.close()
    

    I find it much clearer than the other provided examples.

提交回复
热议问题