Python pickle 的首选(或最常见)文件扩展名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40433474/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Preferred (or most common) file extension for a Python pickle
提问by Raymond Hettinger
This is a question from a student that I didn't have a good answer for. At times, I've seen .pickle, .pck, .pcl, and .dbfor files that contain Python pickles but am unsure what is the most common or best practice. I know that the latter three extensions are also used for other things.
这是一个学生提出的问题,我没有很好的答案。有时,我已经看到.pickle, .pck, .pcl, 和.db包含 Python pickles 的文件,但我不确定什么是最常见或最佳实践。我知道后三个扩展也用于其他事情。
The related question is what MIME type is preferred for sending pickles between systems using a REST API?
相关的问题是在使用 REST API 的系统之间发送泡菜时首选哪种 MIME 类型?
回答by TheoretiCAL
Python 2
蟒蛇 2
From the Python 2 docs:
来自Python 2 文档:
output = open('data.pkl', 'wb')
output = open('data.pkl', 'wb')
I would choose .pklas the extension when using Python 2.
.pkl使用 Python 2 时,我会选择作为扩展名。
Python 3
蟒蛇 3
The example in the Python 3 docsnow uses .pickleas the file extension:
Python 3 文档中的示例现在.pickle用作文件扩展名:
with open('data.pickle', 'rb') as f:
with open('data.pickle', 'rb') as f:
The MIME type preferred for sending pickles from martineau's comment below:
首选用于从 martineau 的以下评论中发送泡菜的 MIME 类型:
application/octet-stream
应用程序/八位字节流
See What is the HTTP "content-type" to use for a blob of bytes?

