问题
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