I think you are missing the fetch call. The cursor only executed your query, but hasn't fetched any thing out.
On Tue, Jun 11, 2013 at 12:20 PM, Khalid Al-Ghamdi <emailkg...@gmail.com>wrote: > Hi, > > I have a dictionary with keys as employee badges and values as their > names. Both key and value are strings. > > I want to read the badges from a sql select and use that to look up the > names in the dictionary. But since the result is a tuple, it doesnt' work. > > how can i overcome this? > > > 1. >>> for data in cur.execute('select badge from sched'): > 2. r_data()[data] > 3. > 4. > 5. Traceback (most recent call last): > 6. File "<pyshell#19>", line 2, in <module> > 7. r_data()[data] > 8. KeyError: (80385,) > > PS: the r_data () above is just a func that returns the before > mentioned dictionary. Here is r_data(). > > 1. def r_data(): > 2. d={} > 3. with open('data.csv') as f: > 4. reader = csv.reader(f) > 5. for sn, badge, name, grp, major, track, stage, tc, > subject, course in reader: > 6. d[badge]=name > 7. return d > > > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > -- Todd Matsumoto
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor