-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
36 lines (24 loc) · 760 Bytes
/
Copy pathutils.py
File metadata and controls
36 lines (24 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import json
import csv
def read_json(file_path):
with open(file_path, 'r') as f:
return json.load(f)
def write_json(data, file_path):
with open(file_path, 'w') as f:
json.dump(data, f, indent=4)
def read_csv(file_path):
with open(file_path, 'r') as f:
return list(csv.DictReader(f))
def write_csv(data, file_path):
if not data:
return
with open(file_path, 'w', newline='') as f:
writer = csv.DictWriter(f, fieldnames=data[0].keys())
writer.writeheader()
writer.writerows(data)
def merge_dicts(dict1, dict2):
merged = dict1.copy()
merged.update(dict2)
return merged
def flatten_list(nested_list):
return [item for sublist in nested_list for item in sublist]