Based on couple of Api Calls I have constructed the following data structure (Dictionary). I have used python dictionary as a holding place.
325167 A,
953929 B, A, C
824420 D, B,
796992 K, M, Z,
825116 J, F, E,
I take the each value, and send a query to the database and get a results set select something from some_table where some_table.someCol = ‘A’. Then I am trying to save this data in another dictionary to use it in future.
This is the error I am currently trying to deal, cl_to is the column name of the query that focusing.
Traceback (most recent call last):
File "Category.py", line 148, in <module>
categoryResults.append(categoryRow['cl_to']);
TypeError: 'NoneType' object is not subscriptable
{'cl_to': 'EP-plater_etter_\xc3\xa5r'}
{'cl_to': 'Musikk_i_2002'}
None
This is how my code looks like:
#Dictionary to save initial category with the rest of cl_to
baseCategoryTree = {}
categoryResults = []
# query get all the categories a category is linked to
categoryQuery = "select cl_to from sometable cl left join anotherTable p on cl.cl_from = p.another_column where p.some_column=14 and p.another_column ='";
cursor = db.cursor(cursors.SSDictCursor);
for key, value in idTitleDictionary.iteritems():
for startCategory in value[0]:
#print startCategory + "End of Query";
try:
baseCategoryTree[startCategory] = [];
#print categoryQuery + startCategory;
cursor.execute(categoryQuery + startCategory + "'");
done = False;
while not done:
categoryRow = cursor.fetchone();
print categoryRow;
if not categoryRow:
done = True;
continue;
categoryResults.append(categoryRow['cl_to']);
baseCategoryTree[startCategory].append(categoryResults);
except Exception, e:
traceback.print_exc();
Best;
N-H
…
…
continuewill wrap to thewhileabove it at which pointcategoryRowis going to be None.Then when:
is encountered… boom.
You probably want the following if you want to capture all rows:
…
…