Python pickle的首选(或最常见)文件扩展名 [英] Preferred (or most common) file extension for a Python pickle

查看:1205
本文介绍了Python pickle的首选(或最常见)文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个学生提出的问题,我没有一个很好的答案.有时,对于包含Python泡菜但不确定最常见或最佳做法的文件,我曾见过.pickle.pck.pcl.db.我知道后三个扩展也用于其他用途.

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.

相关的问题是,使用REST API在系统之间发送酱菜时,首选哪种MIME类型?

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

推荐答案

Python 2

Python 2文档:

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

在使用Python 2时,我会选择.pkl作为扩展名.

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

Python 3

Python 3文档中的示例现在使用.pickle作为文件扩展名:

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

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


从以下martineau的评论中发送咸菜的首选MIME类型:


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

应用程序/八位字节流

application/octet-stream

请参见>什么是字节HTTP内容类型"用一个字节的字节?

这篇关于Python pickle的首选(或最常见)文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆