Reputation: 457
i try to do a python's scraping script who takes informations and put it in a json file,
but the problem is i don't know how go to a newline after my information. MY json file is:
Test1:blablablablaTest2:Blablabal:Test3BLABLABLA etc...
and i want
Test1:blablabl
test2:blablabla
etc
there is my code: (i tried to put '\n' but it writes \n at the end of the line)
with open(source, 'w', encoding='utf-8') as f:
json.dump(date_json, f, ensure_ascii=False, indent=2)
json.dump(numeroFacture_json, f, ensure_ascii=False, indent=2)
json.dump(montantTotal_json, f, ensure_ascii=False, indent=2)
json.dump(tva_json, f, ensure_ascii=False, indent=2)
json.dump(montantHt_json, f, ensure_ascii=False, indent=2)
Thanks!
Upvotes: 2
Views: 2798
Reputation: 267
To do that, just add f.write("\n")
after each json.dump
sentence, so like this:
with open(source, 'w', encoding='utf-8') as f:
json.dump(date_json, f, ensure_ascii=False, indent=2)
f.write("\n")
json.dump(numeroFacture_json, f, ensure_ascii=False, indent=2)
f.write("\n")
json.dump(montantTotal_json, f, ensure_ascii=False, indent=2)
f.write("\n")
json.dump(tva_json, f, ensure_ascii=False, indent=2)
f.write("\n")
json.dump(montantHt_json, f, ensure_ascii=False, indent=2)
Upvotes: 2