Skip to content

Instantly share code, notes, and snippets.

@cluelesscoder
Last active December 17, 2015 13:19
Show Gist options
  • Save cluelesscoder/5616667 to your computer and use it in GitHub Desktop.
Save cluelesscoder/5616667 to your computer and use it in GitHub Desktop.
random issue: list indices must be integers not tuple python
import sqlite3
from collections import defaultdict
DATABASE = 'C:/Misc/myscripts/workprototype/workprototype.db'
conn = sqlite3.connect(database=DATABASE)
comp = conn.execute('select companies.name from companies')
comp = [dict(co_name=row[0]) for row in comp.fetchall()]
prod = conn.execute('select c.name, p.name, c.desc, p.desc from companies c inner join products p on c.co_id = p.co_id')
prod = [dict(co_name=row[0], co_desc=row[1],prod_name=row[2], prod_desc=row[3]) for row in prod.fetchall()]
test = prod[0]['co_name']
print test
ordered = defaultdict(lambda:defaultdict(list))
prod_dict = {}
for idx, val in enumerate(comp):
ordered['co_name'].append(val['co_name'])
for id2, val in enumerate(prod):
if comp[idx]['co_name'] == prod[id2]['co_name']:
prod_dict.append(prod[id2])
#ordered[idx] = comp[idx]['co_name']
#ordered.append(prod[idx]['prod_name'])
#ordered.append(prod[idx])
import stayopen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment