trying to populate wxchoice with data from my db

Dolamite Jenkins
Dolamite Jenkins used Ask the Experts™
Ok I'm getting close but I cant figure out what Im doing wrong... im trying to populate my wxchoice with the first column of my db table ... in the case 'nameofevent' but I keep getting the error

File "C:\Python26\",line1363, in__init__
s['Nameofevent'] = row['nameofevent']
TypeError: tuple indices must be integers, not str

            con = lite.connect('eventpreplannerII.sqlite')
            cur = con.cursor()
            cur.execute("select * from eventinfoII" )
            print rows
            print rRows
            for row in rows:
                s['Nameofevent']  =row['nameofevent'] 
                self.nameofevet1 = s['nameofevent']
                wx.Choice(self,-1,(255,255), choices = self.nameofevet1)
            wx.Choice(self,-1,(255,255), choices = rRows)
        except lite.Error, error:
            dlg = wx.MessageDialog(self, str(error), 'Error occured')

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
The cursor you use is not a dictionary cursor so the result stored in the variable rows is a list of tuples and not a list of dictionaries. Subsequently the variable row that iterates over rows is a tuple.

You should either use:

s['Nameofevent'] =row[n]
where n is the position of the column you want to get starting from 0


you could implement yourself the dictionary cursor and use the original implementation

I have attached the code for the implementation with a use example in case you want to go that way and in the comments of the code is the url of the python docs that explain it further.
#Code from qlite3 — DB-API 2.0 interface for SQLite databases
#11.13.2. Connection Objects¶

import sqlite3

def dict_factory(cursor, row):
    d = {}
    for idx, col in enumerate(cursor.description):
        d[col[0]] = row[idx]
    return d

con = sqlite3.connect(":memory:")
con.row_factory = dict_factory
cur = con.cursor()
cur.execute("select 1 as a")
print cur.fetchone()["a"]

Open in new window


got me part of the way

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial