Answer the question
In order to leave comments, you need to log in
Error when rewriting json via python?
I wrote a BASH script, I needed a base, I decided to make it on json, overwrite it using python, and then parse it using JQ, I hadn’t done a base on json before, as a result, after a lot of trial and error, everything finally worked, then I added the keys (also for the first time) and everything stopped working
#!/usr/bin/env python
import argparse
import json
parser = argparse.ArgumentParser(description="test")
parser.add_argument("-i", dest="id", required=True)
parser.add_argument("-a", dest="api", required=True)
args = parser.parse_args()
def a(id, api):
with open("tg.json", "rt", encoding="utf-8") as file:
settings = json.load(file)
settings["id"] = {id}
settings["api"] = {api}
with open("tg.json", "wt", encoding="utf-8") as file:
json.dump(settings, file, indent=4)
print ({id})
rc, message = a(args.id, args.api)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question