-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod_data_loader.py
More file actions
30 lines (26 loc) · 867 Bytes
/
mod_data_loader.py
File metadata and controls
30 lines (26 loc) · 867 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
# mod_data_loader.py
import csv
import json
def load_data(file_path):
"""
Loads data from a CSV or JSON file.
Parameters:
file_path (str): Path to the data file.
Returns:
list of dict: List containing data entries.
"""
data = []
try:
if file_path.endswith('.csv'):
with open(file_path, 'r', encoding='utf-8') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
data.append(row)
elif file_path.endswith('.json'):
with open(file_path, 'r', encoding='utf-8') as jsonfile:
data = json.load(jsonfile)
else:
raise ValueError("Unsupported file format. Use CSV or JSON.")
except Exception as e:
print(f"Error loading data: {e}")
return data