MCPcopy Index your code
hub / github.com/zai-org/CodeGeeX / dicts_to_jsonl

Function dicts_to_jsonl

codegeex/benchmark/execution.py:15–41  ·  view source on GitHub ↗

Method saves list of dicts into jsonl file. :param data: (list) list of dicts to be stored, :param filename: (str) path to the output file. If suffix .jsonl is not given then methods appends .jsonl suffix into the file. :param compress: (bool) should file be compressed into

(data_list: list, filename: str, compress: bool = True)

Source from the content-addressed store, hash-verified

13from typing import *
14
15def dicts_to_jsonl(data_list: list, filename: str, compress: bool = True) -> None:
16 """
17 Method saves list of dicts into jsonl file.
18 :param data: (list) list of dicts to be stored,
19 :param filename: (str) path to the output file. If suffix .jsonl is not given then methods appends
20 .jsonl suffix into the file.
21 :param compress: (bool) should file be compressed into a gzip archive?
22 """
23 sjsonl = '.jsonl'
24 sgz = '.gz'
25 # Check filename
26 if not filename.endswith(sjsonl):
27 filename = filename + sjsonl
28 # Save data
29
30 if compress:
31 filename = filename + sgz
32 with gzip.open(filename, 'w') as compressed:
33 for ddict in data_list:
34 jout = json.dumps(ddict) + '\n'
35 jout = jout.encode('utf-8')
36 compressed.write(jout)
37 else:
38 with open(filename, 'w') as out:
39 for ddict in data_list:
40 jout = json.dumps(ddict) + '\n'
41 out.write(jout)
42
43
44def check_correctness(

Callers

nothing calls this directly

Calls 2

encodeMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected