arrays - Access python member from object without dict -
this small piece of application i'm having issues @ moment.
import csv open('eggs.csv', 'rb') csvfile: reader = csv.dictreader(csvfile) row in reader: print(row['first_name'], row['cat']) print(row[1])
the application section runs fine no issues, wanted access each value 'row' means of ith element or through numerical value.
however, doesn't seem function expected.
is there specific way should doing access member items without having directly call column name.
help , clarification appreciated.
the csv
module gives 2 broad ways of accessing data each line of file:
- by index, using
reader
; or - by key, using
dictreader
.
however, note dictreader
instance has fieldnames
attribute, "a sequence elements associated fields of input data in order", convert index key use:
row[reader.fieldnames[1]]
Comments
Post a Comment