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:

  1. by index, using reader; or
  2. 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

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -