Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试使用输入为 CSV 为每一行生成单独的 JSON 文件并保存到输出文件夹中。使用循环逻辑。
假设data是您的问题中定义的字典,则以下代码可以满足您的要求:
data
data_path = 'C:/Users/usasxs174/Desktop/ETL/Data_tables/MT/' for i, data_item in enumerate(data['entities']): with open(data_path + str(i) + '.json', 'w') as outfile: outfile.write(json.dumps(data_item, indent=4))