Index Python fetchall()
<p>I'm trying to figure out how to use Python with MySQL. I'm having trouble addressing entries in the query results.</p>

<p>So if I do something like this:  </p>

<pre><code>import MySQLdb

db = MySQLdb.connect(host="192.168.178.10",
                     user="user",
                     passwd="password",
                     db="testdb")

cur = db.cursor()

cur.execute("select * from Persons;")
print(cur.fetchall()[2][2])


db.close()
</code></pre>

<p>I get the third entry of the third row which seems plausible.</p>

<p>If I do this:</p>

<pre><code>print(cur.fetchall()[0][0:2])
</code></pre>

<p>I get the first to entries of the first row. Which also seems plausible.</p>

<p>However if I do something like this:</p>

<pre><code>print(cur.fetchall()[0:2][2])
</code></pre>

<p>I get the error:</p>

<pre><code>Traceback (most recent call last):
  File "mysql.py", line 19, in &lt;module&gt;
    print(cur.fetchall()[0:2][2])
IndexError: tuple index out of range
</code></pre>

<p>Which I do not understand.</p>

<p>Also I am unable to get (for example) all the first entries of all the rows. To achieve this it seems I need to do a loop through the entries I want.</p>

<p>Could someone clarify what I'm doing wrong or how this works?</p>

<p>Greetings! </p>