MCPcopy Create free account
hub / github.com/Tencent/digitalhuman / load_data

Function load_data

SWF/src/utils.py:29–44  ·  view source on GitHub ↗
(filename, file_type=None)

Source from the content-addressed store, hash-verified

27
28
29def load_data(filename, file_type=None):
30 if file_type is None:
31 file_type = ['json']
32 if filename.endswith('.jsonl'):
33 return [json.loads(line) for line in open(filename)]
34 elif filename.endswith('.json'):
35 return json.load(open(filename, 'r'))
36 elif os.path.isdir(filename):
37 files = [os.path.join(filename, f) for f in os.listdir(filename) if any(f.endswith(ext) for ext in file_type)]
38 return [load_data(f) for f in files]
39 elif filename.endswith('.txt'):
40 with open(filename, 'r') as f:
41 data = [line.strip() for line in f]
42 return data
43 else:
44 raise "no suitable function to load data"
45
46
47def write_file(filename, data):

Callers 2

mainFunction · 0.90
baseline.pyFile · 0.90

Calls 1

loadMethod · 0.45

Tested by

no test coverage detected