TypeError: list indices must be integers, not str. Know the issue, not the answer
<p>Unique situation, I know the problem, just dont know a solution. </p>

<pre><code>import string

timefile = open('lasttimemultiple.txt','r+')#opens the file that contains the        last time run
lasttime = timefile.read()#reads the last time file
items= int(2)

splitlines = string.split(lasttime,'\n')
print splitlines[items][0:2]
timefile.close() #closes last time
PullType = '00'
datapt = '01'
for items in splitlines:
if splitlines[items][0:2] == PullType:
    datapt = splitlines[items]
else:
    print ''

print datapt
</code></pre>

<p>I know my issue is I am using 'items' as the index I am calling versus an integer, but I don't know how to use a reference to work through the data without using an non-int variable name. </p>

<p>Any ideas how to achieve this?
Thanks</p>

<p>You should show the actual traceback. If you had, you would have seen that the error is in this line:</p>

<pre><code>if splitlines[items][0:2] == PullType:
</code></pre>

<p>That's because <code>items</code> here has been redefined by the for loop in the line before. In a for loop in Python, the variable is not a counter, it is the actual item from that iteration. So, in the first iteration, <code>items</code> is the first element of splitlines, etc. So it is a string, not an integer. The fix is to use it directly:</p>

<pre><code>if items[0:2] == PullType:
</code></pre>

<p>(Also, you should think about better variable names: that should be <code>item</code>, not <code>items</code>).</p>

python