looking for some solutions? You are welcome.

SOLVED: How to find and change all json.gz files by python

zxz123:

I have a folder, which has many sub folders, and in these sub folders is json.gz file with the same name.And these json files are with the same structure.
Such as ...\a\0\b.json.gz
...\a\1\b.josn.gz
...\a\2\b.josn.gz
What I want to do is give the path to .../a then alter a certain value in the json file.

My code is like this:

def getAllSourceFile(folder):
arrSource = []
for root,dirs,files in os.walk(folder):
    for file in files:
        if file.__str__()=='b.json.gz':
            allSourceFile = os.path.join(root,file)
            arrSource.append(allSourceFile)

return arrSource                        

def ModRootFile(rootM_file,Scale):
f=gzip.open(rootM_file,'r')
file_content=f.read()
f.close()

d=file_content.decode('utf8').split(',')
for i in d:
    doc=d.get(i)
    jsondoc=json.dumps(doc)
    jsondict=json.loads(jsondoc)
    print(i)
    for k in jsondict["2"]:
        k["atlas"]="false"
    d.save(jsondict)

I'm trying to change "atlas" to "false", it finished without error, or at least without error hint.but nothing changed.
Could some one please tell me what is wrong? Thank you.



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent