how to skip blank line while reading CSV file using python

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

    You can always check for the number of comma separated values. It seems to be much more productive and efficient.

    When reading the lines iteratively, as these are a list of comma separated values you would be getting a list object. So if there is no element (blank link), then we can make it skip.

            with open(filename) as csv_file:
              csv_reader = csv.reader(csv_file, delimiter=",")
              for row in csv_reader:
                if len(row) == 0:
                    continue
    

提交回复
热议问题