how to skip blank line while reading CSV file using python

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

    import csv
    
    with open('userlist.csv') as f:
    
        reader = csv.reader(f)
        user_header = next(reader)       # Add this line if there the header is
    
        user_list = []                   # Create a  new user list for input
        for row in reader:
            if any(row):                 # Pick up the non-blank row of list
                print (row)              # Just for verification
                user_list.append(row)    # Compose all the rest data into the list
    

提交回复
热议问题