Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="node65.html" /> | |
13 | <link rel="prev" href="node63.html" /> | |
14 | <link rel="parent" href="module-pickle.html" /> | |
15 | <link rel="next" href="node65.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>3.14.2 Data stream format</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="3.14.1 Relationship to other" | |
25 | href="node63.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="3.14 pickle " | |
28 | href="module-pickle.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="3.14.3 Usage" | |
31 | href="node65.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="node63.html">3.14.1 Relationship to other</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="module-pickle.html">3.14 pickle </A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="node65.html">3.14.3 Usage</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H2><A NAME="SECTION0051420000000000000000"> | |
56 | 3.14.2 Data stream format</A> | |
57 | </H2> | |
58 | ||
59 | <P> | |
60 | The data format used by <tt class="module">pickle</tt> is Python-specific. This has | |
61 | the advantage that there are no restrictions imposed by external | |
62 | standards such as XDR<a id='l2h-632' xml:id='l2h-632'></a> | |
63 | (which can't represent pointer sharing); however it means that | |
64 | non-Python programs may not be able to reconstruct pickled Python | |
65 | objects. | |
66 | ||
67 | <P> | |
68 | By default, the <tt class="module">pickle</tt> data format uses a printable ASCII | |
69 | representation. This is slightly more voluminous than a binary | |
70 | representation. The big advantage of using printable ASCII (and of | |
71 | some other characteristics of <tt class="module">pickle</tt>'s representation) is that | |
72 | for debugging or recovery purposes it is possible for a human to read | |
73 | the pickled file with a standard text editor. | |
74 | ||
75 | <P> | |
76 | There are currently 3 different protocols which can be used for pickling. | |
77 | ||
78 | <P> | |
79 | ||
80 | <UL> | |
81 | <LI>Protocol version 0 is the original ASCII protocol and is backwards | |
82 | compatible with earlier versions of Python. | |
83 | ||
84 | <P> | |
85 | </LI> | |
86 | <LI>Protocol version 1 is the old binary format which is also compatible | |
87 | with earlier versions of Python. | |
88 | ||
89 | <P> | |
90 | </LI> | |
91 | <LI>Protocol version 2 was introduced in Python 2.3. It provides | |
92 | much more efficient pickling of new-style classes. | |
93 | ||
94 | <P> | |
95 | </LI> | |
96 | </UL> | |
97 | ||
98 | <P> | |
99 | Refer to PEP 307 for more information. | |
100 | ||
101 | <P> | |
102 | If a <var>protocol</var> is not specified, protocol 0 is used. | |
103 | If <var>protocol</var> is specified as a negative value | |
104 | or <tt class="constant">HIGHEST_PROTOCOL</tt>, | |
105 | the highest protocol version available will be used. | |
106 | ||
107 | <P> | |
108 | ||
109 | <span class="versionnote">Changed in version 2.3: | |
110 | The <var>bin</var> parameter is deprecated and only provided | |
111 | for backwards compatibility. You should use the <var>protocol</var> | |
112 | parameter instead.</span> | |
113 | ||
114 | <P> | |
115 | A binary format, which is slightly more efficient, can be chosen by | |
116 | specifying a true value for the <var>bin</var> argument to the | |
117 | <tt class="class">Pickler</tt> constructor or the <tt class="function">dump()</tt> and <tt class="function">dumps()</tt> | |
118 | functions. A <var>protocol</var> version >= 1 implies use of a binary format. | |
119 | ||
120 | <P> | |
121 | ||
122 | <DIV CLASS="navigation"> | |
123 | <div class='online-navigation'> | |
124 | <p></p><hr /> | |
125 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
126 | <tr> | |
127 | <td class='online-navigation'><a rel="prev" title="3.14.1 Relationship to other" | |
128 | href="node63.html"><img src='../icons/previous.png' | |
129 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
130 | <td class='online-navigation'><a rel="parent" title="3.14 pickle " | |
131 | href="module-pickle.html"><img src='../icons/up.png' | |
132 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
133 | <td class='online-navigation'><a rel="next" title="3.14.3 Usage" | |
134 | href="node65.html"><img src='../icons/next.png' | |
135 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
136 | <td align="center" width="100%">Python Library Reference</td> | |
137 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
138 | href="contents.html"><img src='../icons/contents.png' | |
139 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
140 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
141 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
142 | <td class='online-navigation'><a rel="index" title="Index" | |
143 | href="genindex.html"><img src='../icons/index.png' | |
144 | border='0' height='32' alt='Index' width='32' /></A></td> | |
145 | </tr></table> | |
146 | <div class='online-navigation'> | |
147 | <b class="navlabel">Previous:</b> | |
148 | <a class="sectref" rel="prev" href="node63.html">3.14.1 Relationship to other</A> | |
149 | <b class="navlabel">Up:</b> | |
150 | <a class="sectref" rel="parent" href="module-pickle.html">3.14 pickle </A> | |
151 | <b class="navlabel">Next:</b> | |
152 | <a class="sectref" rel="next" href="node65.html">3.14.3 Usage</A> | |
153 | </div> | |
154 | </div> | |
155 | <hr /> | |
156 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
157 | </DIV> | |
158 | <!--End of Navigation Panel--> | |
159 | <ADDRESS> | |
160 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
161 | </ADDRESS> | |
162 | </BODY> | |
163 | </HTML> |