python pickle to json
2023-09-14 09:11:53 时间
ref: https://gist.github.com/Samurais/567ebca0f59c612eb977065008aad867
''' Convert a pkl file into json file ''' import sys import os import pickle import json def convert_dict_to_json(file_path): with open(file_path, 'rb') as fpkl, open('%s.json' % file_path, 'w') as fjson: data = pickle.load(fpkl) json.dump(data, fjson, ensure_ascii=False, sort_keys=True, indent=4) def main(): if sys.argv[1] and os.path.isfile(sys.argv[1]): file_path = sys.argv[1] print("Processing %s ..." % file_path) convert_dict_to_json(file_path) else: print("Usage: %s abs_file_path" % (__file__)) if __name__ == '__main__': main()
相关文章
- 第二百九十九节,python操作redis缓存-SortSet有序集合类型,可以理解为有序列表
- JSON.parse 解析json字符串时,遇换行符报错
- python中精确输出JSON浮点数的方法
- 【Python】python对象与json相互转换
- python 虚拟环境篇
- Python 数学运算库Numpy入门基础(一)创建数组
- Python jsonpath库的使用:解析json并将结果保存到文件
- Flutter高级第2篇:JSON的序列化和反序列化、创建模型类转换Json数据
- Python: 爬虫入门-python爬虫入门教程(非常详细)
- Python之ffmpeg-python:ffmpeg-python库的简介、安装、使用方法之详细攻略
- 已解决2.Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and wi
- 〖Python零基础入门篇㉒〗- Python列表常用方法
- Python JSON 数据|编码解码JSON数据,import json,json.dumps,json.loads
- C++调用C++项目中的Python脚本中的函数和类。,在,工程,python
- python中读取json文件报错,TypeError:the Json object must be str, bytes or bytearray,not ‘TextIOWrapper’
- python里怎么样判断文件名和文件实例对象
- python的协程
- 【python】解决json.dump(字典)时报错Object of type ‘float32‘ is not JSON serializable
- 〖Python自动化办公篇⑲〗 - python实现邮件自动化 - 邮件发送
- 〖Python自动化办公篇㉑〗- python实现邮件自动化 - 定时发送邮件
- 第四讲:json(Python实现)
- python使用技巧(三十三):多维列表list数据写入Excel的xlsx文件