-
Notifications
You must be signed in to change notification settings - Fork 6
File Processing
Yimin Jing edited this page Feb 22, 2022
·
7 revisions
import takin
single_json_data = takin.load_single_json("files/single_json.json", prefix="data")
print(single_json_data)
>>> {'name': 'takin', 'email': '[email protected]', 'school': [1, 2, 3]}
multi_json_data = takin.load_multi_json("files/multi_json.json")
print(multi_json_data)
>>> [{'name': 'jingym3', 'age': 25}, {'name': 'zhangsan', 'age': 24}]
single_json_data = takin.load_single_json("files/single_json.json", prefix="data")
multi_json_data = takin.load_multi_json("files/multi_json.json")
takin.write_json(single_json_data, "files/writed_single_json.json")
takin.write_json(multi_json_data, "files/writed_multi_json.json")
paths = takin.output_filenames("files", "json")
print(paths)
>>> ['files/single_json.json', 'files/multi_json.json', 'files/writed_single_json.json', 'files/writed_multi_json.json']
data = takin.load_single_txt("files/single_txt.txt", keep_enter=True)
print(data)
>>> ['敬毅民\n', '张三\n', '李四\n', '王二麻子']
data = takin.load_multi_txt("files/multi_data", file_type="txt", keep_enter=False)
print(data)
>>> ['敬毅民', '张三', '李四', '王五', '中国', '王二麻子']
data = ["123", "2345", "中国人"]
takin.write_txt(data, "/data/yymmjing/Keeping_Projects/Takin/files/writed_txt.txt")
config = takin.load_yaml("files/config.yaml")
print(config)
>>> {'age': {'jin': 'nnhjh', 'oo0': 'nss'}, 'name': ['zhangsan', 'lisi']}
data = {"name": ["张三", "李四"], "age": [13, 14], "school": ["苏州市第一幼儿园", "北京市第三幼儿园"]}
takin.write_excel(data, "files/wrote_excel.xlsx")
ddata = {"name": ["张三", "李四", "王五"], "age": [13, 14, 17], "school": ["苏州市第一幼儿园", "北京市第三幼儿园", "123456789"]}
takin.write_excel(ddata, "files/wrote_excel.xlsx", sheet_name="student")
sata = {"aaaa": ["张三", "李四", "王五"], "bbb": [13, 14, 17], "cccc": ["苏州市第一幼儿园", "北京市第三幼儿园", "123456789"]}
takin.write_excel(sata, "files/wrote_excel.xlsx", sheet_name="woman")