Preferred (or most common) file extension for a Python pickle

徘徊边缘 提交于 2019-12-08 15:38:28

问题


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 .db for 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.

The related question is what MIME type is preferred for sending pickles between systems using a REST API?


回答1:


Python 2

From the Python 2 docs:

output = open('data.pkl', 'wb')

I would choose .pkl as the extension when using Python 2.

Python 3

The example in the Python 3 docs now uses .pickle as the file extension:

with open('data.pickle', 'rb') as f:


The MIME type preferred for sending pickles from martineau's comment below:

application/octet-stream

See What is the HTTP "content-type" to use for a blob of bytes?



来源:https://stackoverflow.com/questions/40433474/preferred-or-most-common-file-extension-for-a-python-pickle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!