Why am I getting a TypeError when looping?
<p>I'm working on a Python extension module, and one of my little test scripts is doing something strange, viz.:</p>

<pre><code>x_max, y_max, z_max = m.size

for x in xrange(x_max):
    for y in xrange(y_max):
        for z in xrange(z_max):
            #do my stuff
</code></pre>

<p>What makes no sense is that the loop gets to the end of the first 'z' iteration, then throws a TypeError, stating that "an integer is required".  If I put a try...except TypeError around it and check the types of x, y, and z, they all come back as &lt; type 'int' >.</p>

<p>Am I missing something here?</p>

<p>EDIT:  It appears I've got a problem somewhere in my extension code.  Pulling out those lines one by one revealed the culprit.  I suspect a reference counting error.  Thanks for the replies.</p>
