LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 12-26-2010, 07:22 PM   #1
felix001
Member
 
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 :

Code:
#!/usr/bin/python

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
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,630
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
You can't access a list as
Code:
print row[2,5,7]
You just need to change it to
Code:
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.
 
  


Reply


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
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
Bash Scripting - Accessing Array Indices Jus144tice Programming 6 10-22-2006 09:20 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


All times are GMT -5. The time now is 03:27 AM.

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