title: Looping through a list of class instances
body: <p>I'm trying to write a Python script that will read a series of loads input through a CSV file, and return the resulting force vector. The format of the CSV is:</p>
  
  <pre><code>x,y,z,load_in_x,load_in_y,load_in_z
  u,v,w,load_in_x,load_in_y,load_in_z
  ...
  </code></pre>
  
  <p>Here is the script:</p>
  
  <pre><code># Fastener class containing an ID, location in space, and load vector
  class Fastener(object):
      """A collection of fasteners"""
      noOfFstnrs = 0
      def __init__(self,xyz,load):
          self.xyz = xyz
          self.load = load
          Fastener.noOfFstnrs += 1
          self.fastID = Fastener.noOfFstnrs
  
      def __repr__(self):
          return """Fastener ID: %s
  Location: %s
  Load: %s""" % (self.fastID, self.xyz, self.load)
  
  
  # Request the mapping CSV file from the user. The format should be:
  # x,y,z,load_in_x,load_in_y,load_in_z
  path = input("Fastener mapping file: ")
  
  with open(path,"r") as inputFile:
      inputLines = inputFile.readlines()
  
  # Create a list of Fastener objects from each line in the mapping file
  F = []
  for line in range(len(inputLines)):
      inputLines[line] = inputLines[line].strip('\n')
      inputLines[line] = inputLines[line].split(",")
      location = [float(i) for i in inputLines[line][:3]]
      load = [float(i) for i in inputLines[line][3:]]
      F.append(Fastener(location,load))
  
  # Function to sum all fastener loads and return the resulting linear force
  # vector
  def sumLin(fastenerList):
      xSum = 0
      ySum = 0
      zSum = 0
      for i in fastenerList:
          xSum += fastenerList[i].load[1]
          ySum += fastenerList[i].load[2]
          zSum += fastenerList[i].load[3]
      linVector = [xSum, ySum, zSum]
      return linVector
  
  # Print 
  print(sumLin(F))
  </code></pre>
  
  <p>When I run it, I keep getting the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "bolt_group.py", line 49, in &lt;module&gt;
      print(sumLin(F))
    File "bolt_group.py", line 42, in sumLin
      xSum += fastenerList[i].load[1]
  TypeError: list indices must be integers, not Fastener
  </code></pre>
  
  <p>I've tried changing the looping index <code>i</code> to <code>int(i)</code> and it still gives me problems. If I manually add them like below there are no problems.</p>
  
  <pre><code>xSum = F[1].load[1] + F[2].load[1] + F[3].load[1]
  </code></pre>