Mar*_*oma 22
在Python文档似乎不是那么好,所以这里是我的尝试.
pip install msgpack
Run Code Online (Sandbox Code Playgroud)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import msgpack
# Define data
data = {'a list': [1, 42, 3.141, 1337, 'help'],
'a string': 'bla',
'another dict': {'foo': 'bar',
'key': 'value',
'the answer': 42}}
# Write msgpack file
with open('data.msgpack', 'w') as outfile:
msgpack.pack(data, outfile)
# Read msgpack file
with open('data.msgpack') as data_file:
# data_loaded = json.load(data_file)
data_loaded = msgpack.unpack(data_file)
print(data == data_loaded)
Run Code Online (Sandbox Code Playgroud)
对于您的应用程序,以下可能很重要:
另请参见:数据序列化格式的比较
如果您正在寻找一种制作配置文件的方法,您可能希望阅读我的简短文章Python中的配置文件
| 归档时间: |
|
| 查看次数: |
13265 次 |
| 最近记录: |