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 - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor