0

I have the following code:

clusters = open('input.txt', 'r')

cluster = raw_input('Enter the name of the cluster: ')
name = []
a = []
b = []
d = []
e = []
c = []
f = []
g = []
h = []

for line in clusters:
    column = line.split()
    name.append(column(0)) 
    if name == cluster:
        a.append(int(column(1)))
        b.append(int(column(2)))
        d.append(int(column(3)))
        e.append(int(column(4)))
        c.append(int(column(5)))
        f.append(int(column(6)))
        g.append(float(column(7)))
        h.append(float(column(8)))
    else:
        print('Cluster data does not exist')  

I am trying to use the first word of the file as a filter so that if it matches the input it will read the rest of the data from that line. However, when I run it I get an error saying:

File "C:/Users/Keith/.spyder2/CMD.py", line 41, in <module>    
name = column(0)
TypeError: 'list' object is not callable

I have looked at a few questions which show how to print a word but I don't know how to just read it and see if it matches the input word.

My input file is like this:

fjji 38 427 18 404 46 630000 0.482 0.271
fjjii 38 481 18 159 35 630000 0.482 0.271
fjjiii 39 38 19 575 41 630000 0.504 0.284
fjjiv 39 122 22 482 35 630000 0.527 0.296
fjjv 39 134 23 49 40 630000 0.529 0.298
fjjvii 39 184 23 36 50 630000 0.527 0.296

Any help would be greatly appreciated, thanks.

Daniel
  • 5,095
  • 5
  • 35
  • 48

2 Answers2

0

Try column[0] instead of column(0) in all occurrences (including where arguments are not zero). Python thinks you're calling a function. You're using the wrong syntax.

TomCho
  • 3,204
  • 6
  • 32
  • 83
  • Will I need to do that for the rest of the variables yeah? – Keith Hardie Mar 09 '15 at 17:57
  • I'm not sure I understand this question. This is the syntax to index lists, so everything you want a given element of a given list you'll need to use this syntax. Given that `column` is a list, you'll have to do it every time you want an element of `column`. The same goes for your lists that are named `a`, `b` and etc. Which reminds me: you should really consider the possibility of using a list of lists on your code. It would make things easier. Check out [this question](http://stackoverflow.com/questions/8189169/nested-lists-python). – TomCho Mar 09 '15 at 18:21
0

You need to use square brackets to index the list returned by line.split()

name.append(column[0])
user3590169
  • 396
  • 2
  • 4