Printing a properly formatted SQLite table in Python
<p>I've written a Python script to add rows to my tables. I decided it would be nice if I could also view my tables with the same script instead of having to either quit the script and run sqlite3 or switch to another shell and run sqlite3. So I wrote up what I expected would give me what I want and it sort of does... This is the part of the script in question:</p>

<pre><code>import sqlite3

conn = sqlite3.connect('stu.db')
c = conn.cursor()

var = 1
while var == 1:

    enquiry = raw_input("What would you like to do?&gt; ")

    enquiry == 'stu db' or enquiry == 'sd':
    c.execute("SELECT * FROM stu")
    conn.commit
</code></pre>

<p>In sqlite3 when you run SELECT * FROM stu you get a nicely formatted table with uniform rows and columns. When I run it here I get a long list of the information in parenthesis instead. It looks sort of like this (I didn't print the actual results as that would violate some Federal laws):</p>

<pre><code>[(1234567890, u'John Doe', 3852, u'DEGR-AA', 4, None), (1234567890, u'John Doe', 3852, u'DEGR-AA', 4, None),(1234567890, u'John Doe', 3852, u'DEGR-AA', 4, None),(1234567890, u'John Doe', 3852, u'DEGR-AA', 4, None),(1234567890, u'John Doe', 3852, u'DEGR-AA', 4, None),(1234567890, u'John Doe', 3852, u'DEGR-AA', 4, None),(1234567890, u'John Doe', 3852, u'DEGR-AA', 4, None),(1234567890, u'John Doe', 3852, u'DEGR-AA', 4, None),(1234567890, u'John Doe', 3852, u'DEGR-AA', 4, None),(1234567890, u'John Doe', 3852, u'DEGR-AA', 4, None)]
</code></pre>

<p>I think I know what's going on. Python is just spitting out what the query to sqlite returns, but is there a way to format this information so that it is easily readable?</p>