i am want to read data from the csv that i wrote using python csv module but apart from filed names and row count i am unable to read rest of the data

Peter Otten __peter__ at web.de
Sun Apr 12 04:24:32 EDT 2020


Rahul Gupta wrote:

> the cells in my csv that i wrote looks likes this
> 
['82#201#426#553#602#621#811#908#1289#1342#1401#1472#1593#1641#1794#2290#2341#2391#3023#3141#3227#3240#3525#3529#3690#3881#4406#4421#4497#4719#4722#4920#5053#5146#5433']
> and the cells which are empty looks like [''] i have tried the following
> code import csv
> import numpy as np
> with open("D:\PHD\obranking\\cell_split_demo.csv", mode='r') as csv_file:
>     csv_reader = csv.DictReader(csv_file)
>     print(csv_reader.fieldnames)
>     col_count = print(len(csv_reader.fieldnames))

>     print(sum(1 for row in csv_file))

The generator expression above consumes the entire file. Remove the line, 
and the rows should be printed below as expected.

>     for line in csv_reader:
>         print(line)
>  but when i print line it shows nothing




More information about the Python-list mailing list