Sep-27-2022, 02:58 AM
Hello looking to see if anyone could help me out here. Ive been trying to figure this out but seem to keep getting stuck. Im not very advance in python however im learning new things each day and time I write or try to write something new...
Long story short, I opening a JSON file pulling out only certain data from the dict once this data is found I print it, however I want to also print this data to a text file. When I'm doing the print statement its only writing the last record to the file when there is a total of around say 500 items printing on my screen.. I cannot for the life of me figure out or see what I am doing wrong... So any help or guidance on this would be great.
Long story short, I opening a JSON file pulling out only certain data from the dict once this data is found I print it, however I want to also print this data to a text file. When I'm doing the print statement its only writing the last record to the file when there is a total of around say 500 items printing on my screen.. I cannot for the life of me figure out or see what I am doing wrong... So any help or guidance on this would be great.
#! /usr/bin/python3.6 # parseJson.py import json f = open('response_1664244998587.json') CONSTRUCT = json.loads(f.read()) for element in CONSTRUCT['data']: try: print(element['id']) except: continue path = "/home/tpolim001/PNCChecker.txt" print("PATH", path) with open(path, "w+") as x: # Write Data to file x.write (element['id']) x.close()