Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 12-26-2010, 07:22 PM   #1
Registered: Jan 2009
Posts: 101

Rep: Reputation: 15
TypeError: list indices must be integers

Im just setting out on the long road to learn python so please excuse my lack of knowledge.
Im initally trying to read a csv in and print only certain "elements" (not sure if thats the right term) from a list. But I am getting the error :

TypeError: list indices must be integers

My Code is :


import csv
import string

reader = csv.reader(open("statement.csv", "rb"))
for row in reader:
        print row[2,5,7]
Old 12-27-2010, 08:52 AM   #2
Senior Member
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
You can't access a list as
print row[2,5,7]
You just need to change it to
print row[2],row[5],row[7]
And a list element is indeed the right term.

Good luck with learning Python!

Last edited by Snark1994; 12-27-2010 at 08:55 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Scripting - Accessing Array Indices Jus144tice Programming 7 01-10-2015 03:39 PM
LXer: OpenLDAP Quick Tips: Check your indices LXer Syndicated Linux News 0 11-26-2008 07:12 PM
TypeError: rpmdb open failed Red Knuckles Fedora 8 11-05-2006 01:40 PM
Can I make indices on a audio track by cdrecord when burning it on a CD-R? takushi Linux - Software 0 02-15-2006 06:31 PM
64-bit integers in C nodger Programming 1 03-31-2005 08:06 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:55 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration