gpt-3.5-turbo-0125· OpenAI
WildChat-4.8M (AI2)
write a python script which iterate file under especify dir and load by json
- User
write a python script which iterate file under especify dir and load by json
- Assistant
import os import json
specify the directory containing the files
directory = 'path/to/directory'
iterate over files in the directory
for filename in os.listdir(directory): if filename.endswith('.json'): file_path = os.path.join(directory, filename) with open(file_path, 'r') as file: data = json.load(file) print(data) # do something with the loaded data from file
Note: replace 'path/to/directory' with the actual path to the directory containing the JSON files.