alex wrote:
> ok, and what about {1:{"id":"1","name":"Alex"},2:
> {"id":"2","name":"Nick"}} format?
> 
> I try to
> i=0
> result = list()
> for row in session.query(...).all():
>     d = row.__dict__.copy()
>     del d['_sa_instance_state']
>     result.append(i)
>     result.append(d)
>     i = i + 1
> 
> but it gives
> { 1, {"id":"1","name":"Alex"}, 2, {"id":"2","name":"Nick"}}

It's giving you just what you ask for: for every row, append two things 
to the list: an integer followed by a dictionary for the row.  (I'm 
dubious about the outer curly braces, though; when I try a similar chunk 
of code, I get "[...]".)

If you want a dictionary whose keys are the values of "i", define 
"result" initially as "result = {}", then in the loop, replace the 
appends by "result[i] = d".  If you just want a list of the row 
dictionaries, drop all the statements involving "i".

-- 
Don Dwiggins
Advanced Publishing Technology


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to