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

sjeik_appie at hotmail.com sjeik_appie at hotmail.com
Tue Apr 14 17:04:41 EDT 2020


   On 12 Apr 2020 12:30, Peter Otten <__peter__ at web.de> wrote:

     Rahul Gupta wrote:

     >     for line in enumerate(csv_reader):
     >         print(line[csv_reader.fieldnames[1]])

     enumerate() generates (index, line) tuples that you need to unpack:

         for index, line in enumerate(csv_reader):
             print(line[csv_reader.fieldnames[1]])

   ==》 Shouldn't that be, e.g:
   print( line[csv_reader.fieldnames[1].index()] )
   Or maybe:
   cols = csv_reader.fieldnames
   print( [[val for val, col in zip(record, cols) if col in ['somecol']] for
   record in csv_reader])
   ?


More information about the Python-list mailing list