python - When appending dictionary to a list, dict. not on a new line each time -
i have function pushes dictionary created function, list. problem i'm having code multiple pushes not show in list each in new line. i've tried many ways, none have given me desired results.
this line pushes created dictionary:
database.xoomdatabase.append(ordenorganiz)
this function creates dictionary:
def orderzoom(self): nombre = contents1 nicenum = orderresult email = contents2 num = contents3 fechaentrega = contents5 global ordenorganiz ordenorganiz = {"num orden": nicenum, "nombre": nombre, "email": email, "num tel/cel": num, "fecha de entrega": fechaentrega} return ordenorganiz
any ideas on getting done?
sounds problem not inserts rather "pretty print" want apply, check out following example uses json.dumps
:
import json ordenorganiz = {"num orden": 1, "nombre": 2, "email": 3, "num tel/cel": 4, "fecha de entrega": 5} lst = [] lst.append(ordenorganiz) lst.append(ordenorganiz) print json.dumps(lst, indent=4, separators=(',', ': '))
output
[ { "fecha de entrega": 5, "nombre": 2, "num tel/cel": 4, "num orden": 1, "email": 3 }, { "fecha de entrega": 5, "nombre": 2, "num tel/cel": 4, "num orden": 1, "email": 3 } ]
Comments
Post a Comment