python - convert sqlalchemy query result to a list of dicts -


i want have result of query converted list of dicts :

result_dict = [{'category': 'failure', 'week': '1209', 'stat': 'tdc_ok', 'severitydue': '2_critic'}, {'category': 'failure', 'week': '1210', 'stat': 'tdc_nok', 'severitydue': '2_critic'}] 

but instead dict, repeated keys:

result_dict = {'category': 'failure', 'week': '1209', 'stat': 'tdc_ok', 'severitydue': '2_critic', 'category': 'failure', 'week': '1210', 'stat': 'tdc_nok', 'severitydue': '2_critic'} 

i result doing :

for u in my_query.all():      result_dict = u.__dict__ 

how can convert sqlalchemy query result list of dicts (each row dict) ?

help please

try

result_dict = [u.__dict__ u in my_query.all()] 

besides type of your result_dict before for loop? it's behaviour rather strange.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -