Download src/utils/io.py from Dhruv1000/tracegrpo: direct link, hf CLI and curl.
- Browser
- Download file 630 Bytes
-
https://huggingface.co/Dhruv1000/tracegrpo/resolve/main/src/utils/io.py
- Command line
-
hf download hf://Dhruv1000/tracegrpo/src/utils/io.py
-
curl -L -o io.py https://huggingface.co/Dhruv1000/tracegrpo/resolve/main/src/utils/io.py
630 Bytes
| """Small IO helpers shared across pipeline stages.""" | |
| from __future__ import annotations | |
| import json | |
| from pathlib import Path | |
| from typing import Any, Iterable, Iterator | |
| def read_jsonl(path: str | Path) -> Iterator[dict[str, Any]]: | |
| with open(path, "r") as f: | |
| for line in f: | |
| line = line.strip() | |
| if line: | |
| yield json.loads(line) | |
| def write_jsonl(path: str | Path, rows: Iterable[dict[str, Any]]) -> None: | |
| path = Path(path) | |
| path.parent.mkdir(parents=True, exist_ok=True) | |
| with open(path, "w") as f: | |
| for row in rows: | |
| f.write(json.dumps(row) + "\n") | |