import json import os path='C:\\Users\\chenyu03\\Desktop\\test\\128_64\\' name=os.listdir(path) for nm in name: dirpath=os.path.join(path,nm) pic_name=os.listdir(dirpath) if pic_name: for i in pic_name: if not i.endswith('.json'): if i.endswith('.txt'): with open(os.path.join(dirpath,i),'r') as f: a=f.read().split(',') new_dict={'rt': {'x': a[2], 'y': a[3]}, 'lt': {'x': a[0], 'y': a[1]}, 'rb': {'x': a[4], 'y': a[5]}, 'lb': {'x': a[6], 'y': a[7]}} with open(os.path.join(dirpath,i[:-4]+'.json'),'w') as load_f: The json.dump = load_dict (new_dict, load_f) Print (load_dict) the else: Print ( "txt file is not in this file ') the else: Print (' empty folder ')
The method used to generate the json txt
Guess you like
Origin blog.csdn.net/weixin_38740463/article/details/90803472
Recommended
Ranking