[Tutor] sqlite question
Khalid Al-Ghamdi
emailkgnow at gmail.com
Tue Jun 11 12:20:20 CEST 2013
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130611/141087bc/attachment.html>
More information about the Tutor
mailing list