title: TypeError: string indices must be integers, not str on Python Dictionary
body: <p>I'm stuck, on what I'm sure is something simple, but I'm just going around in circles now. The following code is a snippet of a script that iterates over some values I've entered into lists and dictionaries and produces text files that I can feed into another program. The problem I'm having is when attempting to loop round the <em>Direction</em> list and have corresponding values from the relevant dictionary print to file I get the following error:</p>
  
  <p>TypeError: string indices must be integers, not str</p>
  
  <pre><code>Direction = ('E', 'NE')
  
  E = {
      'InitialHeading': 0,
      'InitialX': 22.480,
      'InitialY': 0.000,
      'ActiveCurrent': '10y_Current_W'}
  
  NE = {
      'InitialHeading': 45,
      'InitialX': 15.896,
      'InitialY': 15.896,
      'ActiveCurrent': '10y_Current_SW'}
  
  casenumber = 0
  
  for Offset in Direction:
  
              # CREATE INDIVIDUAL TEXT FILES
              casenumber = casenumber + 1
              filename = 'Case%.3d.txt' % casenumber
              f = open(filename, 'w')
              print &gt;&gt;f, 'InitialHeading: ', Offset['InitialHeading']
              print &gt;&gt;f, 'InitialX: ', Offset['InitialX']
              print &gt;&gt;f, 'InitialY: ', Offset['InitialY']
              print &gt;&gt;f, 'ActiveCurrent: ', Offset['ActiveCurrent']
              f.close()
  </code></pre>
  
  <p>If I replace <em>Offset</em> with the name of the dictionary so the line reads as follows:</p>
  
  <pre><code>print &gt;&gt;f, 'InitialHeading: ', E['InitialHeading']
  </code></pre>
  
  <p>Then the output is exactly what I want and I know that <em>Offset</em> is equal to <em>E</em> when I run the file, as I added a line to print the value of <em>Offset</em> to the console window.</p>
  
  <p>Why doesn't it recognise the dictionary name when it's the same value as the variable <em>Offset</em>, which is obtained from the <em>Direction</em> list? This piece of code is from nested for loops, so I need to be able to refer to the lists &amp; dictionaries to obtain the values, rather than a more manual alternative.</p>