<div>I have used fetchall() to insert the values from a table into a tuple. anywhere from 0 - ? many rows could be in this tuple, so it is a row within a row. How do I use a loops to iterate through the nested tuple, and assign the tuples integers and strings to variables, ugh :P
</div>
<div>&nbsp;</div>
<div>The Tables data is like this: </div>
<div>&nbsp;</div>
<div>+---------------------------------------------------------------------------------------------------------------------+</div>
<div>|&nbsp;&nbsp;&nbsp; ID (INT)&nbsp; |&nbsp;&nbsp; Protocol (TEXT)&nbsp; |&nbsp; Name (LONGTEXT)&nbsp;&nbsp;Description (LONGTEXT)&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp; </div>
<div>+---------------------------------------------------------------------------------------------------------------------+</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div><font size="2">
<p>&nbsp;</p>
<p>import MySQLdb</p>
<p>import sys</p>
<p>&nbsp;</p>
<p># find out what this ports function is ----</p>
<p>def grabPortInfo(port):</p>
<p>try:</p>
<p>conn=MySQLdb.connect( host=&quot;<a href="http://www.freesql.org">www.freesql.org</a>&quot;,</p>
<p>user=&quot;portnumbers&quot;,</p>
<p>port=3306,</p>
<p>passwd=&quot;*********&quot;,</p>
<p>db=&quot;portnumbers&quot;)</p>
<p>except MySQLdb.Error, e: </p>
<p>print &quot;Error %d: %s&quot; % (e.args[0], e.args[1]) </p>
<p>print &quot;\n\n WTF!? - portnumbers MySQL DB didn't open&quot;</p>
<p>sys.exit (1)</p>
<p># ------------------</p>
<p>cursor = conn.cursor()</p>
<p>stmt = &quot;SELECT * FROM portnumbers WHERE port=%i&quot; %port</p>
<p>cursor.execute(stmt)</p>
<p>numrows = int(cursor.rowcount)</p>
<p>if numrows == 0:</p>
<p>print &quot;port # not found in database&quot;</p>
<p>elif numrows &gt;= 1:</p>
<p>result = cursor.fetchall()</p>
<p>print len(result)</p>
<p># break tuple into strings with output </p>
<p>myPort = port</p>
<p>myProtocol = result[0|3]</p>
<p>myName = result[0|4]</p>
<p>myDescription = result[0|5]</p>
<p>print &quot;PORT # | PROTOCOL | PORT NAME | PORT DESCRIPTION &quot;</p>
<p>print myPort, myProtocol, myName, myDescription</p>
<p>cursor.close()</p>
<p>conn.close()</p>
<p># end function -------------</p>
<p>&nbsp;</p>
<p>grabPortInfo(22)</p>
<p>&nbsp;</p>
<p>&nbsp;</p></font></div>