Python3 脚本: 将 Msgpack 二进制文件转换为 JSON 文件
以下是一个将 msgpack 二进制文件转换成 json 文件的 Python 脚本:
import msgpack
import json
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('input_file', help='path to the input file')
parser.add_argument('output_file', help='path to the output file')
args = parser.parse_args()
with open(args.input_file, 'rb') as f:
data = msgpack.unpack(f)
with open(args.output_file, 'w') as f:
json.dump(data, f)
使用该脚本,可以通过以下命令将一个名为 input.msgpack 的 msgpack 二进制文件转换成一个名为 output.json 的 json 文件:
python3 script.py input.msgpack output.json
其中,script.py 是脚本文件的名称。该脚本使用了 Python 的 argparse 模块来解析命令行参数,打开二进制文件并使用 msgpack 库解包数据,最后将数据写入 json 文件中。
原文地址: https://www.cveoy.top/t/topic/npbV 著作权归作者所有。请勿转载和采集!