fue*_*zig 12 serialization python-2.x python-3.x dill
为什么
pickle.dumps({}.items())
Run Code Online (Sandbox Code Playgroud)
TypeError: can't pickle dict_items objects在 Python 3.5.2 中失败,但在 Python 2.7.12 中没有?
“腌制”字典
pickle.dumps({})
Run Code Online (Sandbox Code Playgroud)
适用于两个 Python 版本(并且在 Python 2.7.12 中提供与上述命令相同的输出)。
Jea*_*bre 18
because in python 2.7 .items() returns a mere list of tuples, which is picklable.
In python 3.x it returns a dict_items object (that doesn't exist in python 2), not picklable (but faster since it doesn't generate a list, it's the rough equivalent of python 2.x iteritems()).
But you can force list conversion to simulate python 2.x behaviour:
pickle.dumps(list(d.items()))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13117 次 |
| 最近记录: |