#clearing json file before dump
12 messages · Page 1 of 1 (latest)
in simple, just need to know how to clear a file
tried using .truncate(0) but it comes up with this?
I'd just open at as read then open it as write
with open('data.json') as f:
data = json.load(f)
# modify
with open('data.json', 'w') as f:
json.dump(data, f, indent=4)
wouldnt it still append to the end of the json like that?
No, 'w' truncates
ah
yes using w will fix it
I've never had good experiences with opening as multiple things like 'r+' but that might be a
😄
@true mango has been given 4 kudos from @quiet kelp.
@keen horizon has been given 4 kudos from @quiet kelp.