Download src/utils/jsonl.py from smallan13/DebateCoder: direct link, hf CLI and curl.
- Browser
- Download file 621 Bytes
-
https://huggingface.co/smallan13/DebateCoder/resolve/c7a0d4bb35b29abc02cb9891bd19979bf3eab7ad/src/utils/jsonl.py
- Command line
-
hf download hf://smallan13/DebateCoder@c7a0d4bb35b29abc02cb9891bd19979bf3eab7ad/src/utils/jsonl.py
-
curl -L -o jsonl.py https://huggingface.co/smallan13/DebateCoder/resolve/c7a0d4bb35b29abc02cb9891bd19979bf3eab7ad/src/utils/jsonl.py
621 Bytes
| import json | |
| # Read an jsonl file and convert it into a python list of dictionaries. | |
| def read_jsonl(filename): | |
| """Reads a jsonl file and yields each line as a dictionary""" | |
| lines = [] | |
| with open(filename, "r", encoding="utf-8") as file: | |
| for line in file: | |
| lines.append(json.loads(line)) | |
| return lines | |
| # Write a python list of dictionaries into a jsonl file | |
| def write_jsonl(filename, lines): | |
| """Writes a python list of dictionaries into a jsonl file""" | |
| with open(filename, "w", encoding="utf-8") as file: | |
| for line in lines: | |
| file.write(json.dumps(line) + "\n") | |