Spaces:
Sleeping
Sleeping
File size: 551 Bytes
8521f60 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
"""I/O utilities (e.g., dataset loading, model caching)."""
from pathlib import Path
from typing import List, Dict, Any, Iterable
import json
def read_jsonl(path: Path) -> List[Dict[str, Any]]:
"""Read a JSON Lines file into a list of dicts."""
with path.open() as f:
return [json.loads(line) for line in f]
def write_jsonl(path: Path, rows: Iterable[Dict[str, Any]]) -> None:
"""Write a list/iterable of dicts as JSON Lines."""
with path.open("w") as f:
for row in rows:
f.write(json.dumps(row) + "\n")
|