Jun-06-2018, 09:23 AM
Hi Python Experts,
I am trying to open a json file, modify the content and write it to a different directory.
The code runs but nothing is really happening.
I am not sure what should come first, the dump or the misc save. Is the dump a save as well?
I am trying to open a json file, modify the content and write it to a different directory.
The code runs but nothing is really happening.
I am not sure what should come first, the dump or the misc save. Is the dump a save as well?
from scipy import ndimage, misc import numpy as np import os import cv2 import json def main(): outPath='C:/..../' path='C:/...../data_aug_test/' # iterate through the names of contents of the folder for file_path in os.listdir(path): #create the full input path and read the file input_path = os.path.join(path, file_path) if file_path.endswith('.jpg'): print('jpeg process') else: #.json print('else json handling') with open(input_path, 'r') as f: data = json.load(f) data['id'] = 134 # <--- modify value. #write file then save jsonsavepath = os.path.join(outPath, 'flipped_'+file_path) misc.imsave(jsonsavepath, f) with open(input_path, 'w') as f: json.dump(data, f, indent=4) if __name__ == '__main__': main()