<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mscneuro.neuro.uni-bremen.de/index.php?action=history&amp;feed=atom&amp;title=Pickle%3A_save_and_load_Python_objects</id>
	<title>Pickle: save and load Python objects - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mscneuro.neuro.uni-bremen.de/index.php?action=history&amp;feed=atom&amp;title=Pickle%3A_save_and_load_Python_objects"/>
	<link rel="alternate" type="text/html" href="https://mscneuro.neuro.uni-bremen.de/index.php?title=Pickle:_save_and_load_Python_objects&amp;action=history"/>
	<updated>2026-04-17T01:54:29Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://mscneuro.neuro.uni-bremen.de/index.php?title=Pickle:_save_and_load_Python_objects&amp;diff=335&amp;oldid=prev</id>
		<title>Davrot at 16:20, 17 October 2025</title>
		<link rel="alternate" type="text/html" href="https://mscneuro.neuro.uni-bremen.de/index.php?title=Pickle:_save_and_load_Python_objects&amp;diff=335&amp;oldid=prev"/>
		<updated>2025-10-17T16:20:00Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 16:20, 17 October 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;== The goal ==&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;How to store Python objects in files and how to restore them.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;How to store Python objects in files and how to restore them.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wiki:diff:1.41:old-162:rev-335:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Davrot</name></author>
	</entry>
	<entry>
		<id>https://mscneuro.neuro.uni-bremen.de/index.php?title=Pickle:_save_and_load_Python_objects&amp;diff=162&amp;oldid=prev</id>
		<title>Davrot: Created page with &quot; == The goal == How to store Python objects in files and how to restore them.  Questions to [mailto:davrot@uni-bremen.de David Rotermund]  &#039;&#039;&#039;Warning The pickle module is not secure. Only unpickle data you trust.&#039;&#039;&#039;  == [https://docs.python.org/3/library/pickle.html#module-pickle pickle] == &lt;blockquote&gt;The [https://docs.python.org/3/library/pickle.html#module-pickle pickle] module implements binary protocols for serializing and de-serializing a Python object structure....&quot;</title>
		<link rel="alternate" type="text/html" href="https://mscneuro.neuro.uni-bremen.de/index.php?title=Pickle:_save_and_load_Python_objects&amp;diff=162&amp;oldid=prev"/>
		<updated>2025-10-15T15:28:10Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot; == The goal == How to store Python objects in files and how to restore them.  Questions to [mailto:davrot@uni-bremen.de David Rotermund]  &amp;#039;&amp;#039;&amp;#039;Warning The pickle module is not secure. Only unpickle data you trust.&amp;#039;&amp;#039;&amp;#039;  == [https://docs.python.org/3/library/pickle.html#module-pickle pickle] == &amp;lt;blockquote&amp;gt;The [https://docs.python.org/3/library/pickle.html#module-pickle pickle] module implements binary protocols for serializing and de-serializing a Python object structure....&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
== The goal ==&lt;br /&gt;
How to store Python objects in files and how to restore them.&lt;br /&gt;
&lt;br /&gt;
Questions to [mailto:davrot@uni-bremen.de David Rotermund]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Warning The pickle module is not secure. Only unpickle data you trust.&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== [https://docs.python.org/3/library/pickle.html#module-pickle pickle] ==&lt;br /&gt;
&amp;lt;blockquote&amp;gt;The [https://docs.python.org/3/library/pickle.html#module-pickle pickle] module implements binary protocols for serializing and de-serializing a Python object structure. “Pickling” is the process whereby a Python object hierarchy is converted into a byte stream, and “unpickling” is the inverse operation, whereby a byte stream (from a binary file or bytes-like object) is converted back into an object hierarchy.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [https://docs.python.org/3/library/pickle.html#pickle.dump pickle.dump] and [https://docs.python.org/3/library/pickle.html#pickle.dumps pickle.dumps] ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;pickle.dump(obj, file, protocol=None, *, fix_imports=True, buffer_callback=None)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;blockquote&amp;gt;Write the pickled representation of the object obj to the open file object file. This is equivalent to Pickler(file, protocol).dump(obj).&lt;br /&gt;
&lt;br /&gt;
Arguments file, protocol, fix_imports and buffer_callback have the same meaning as in the Pickler constructor.&amp;lt;/blockquote&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;pickle.dumps(obj, protocol=None, *, fix_imports=True, buffer_callback=None)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;blockquote&amp;gt;Return the pickled representation of the object obj as a bytes object, instead of writing it to a file.&lt;br /&gt;
&lt;br /&gt;
Arguments protocol, fix_imports and buffer_callback have the same meaning as in the Pickler constructor.&amp;lt;/blockquote&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;import pickle&lt;br /&gt;
import numpy as np&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class Example:&lt;br /&gt;
    a: int&lt;br /&gt;
    b: float&lt;br /&gt;
    c: np.ndarray&lt;br /&gt;
&lt;br /&gt;
    def __init__(self) -&amp;gt; None:&lt;br /&gt;
        super().__init__()&lt;br /&gt;
        self.a = 0&lt;br /&gt;
        self.b = 0&lt;br /&gt;
        self.c = np.zeros((1, 2))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
instance_to_save = Example()&lt;br /&gt;
instance_to_save.a = 1&lt;br /&gt;
instance_to_save.b = 2&lt;br /&gt;
instance_to_save.c[0, 0] = 3&lt;br /&gt;
instance_to_save.c[0, 1] = 4&lt;br /&gt;
&lt;br /&gt;
with open(&amp;quot;test.pkl&amp;quot;, &amp;quot;wb&amp;quot;) as file:&lt;br /&gt;
    pickle.dump(instance_to_save, file)&lt;br /&gt;
&lt;br /&gt;
print(instance_to_save.a)  # -&amp;gt; 1&lt;br /&gt;
print(instance_to_save.b)  # -&amp;gt; 2&lt;br /&gt;
print(instance_to_save.c)  # -&amp;gt; [[3. 4.]]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [https://docs.python.org/3/library/pickle.html#pickle.load pickle.load] and [https://docs.python.org/3/library/pickle.html#pickle.loads pickle.loads] ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;pickle.load(file, *, fix_imports=True, encoding=&amp;#039;ASCII&amp;#039;, errors=&amp;#039;strict&amp;#039;, buffers=None)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;blockquote&amp;gt;Read the pickled representation of an object from the open file object file and return the reconstituted object hierarchy specified therein. This is equivalent to Unpickler(file).load().&lt;br /&gt;
&lt;br /&gt;
The protocol version of the pickle is detected automatically, so no protocol argument is needed. Bytes past the pickled representation of the object are ignored.&lt;br /&gt;
&lt;br /&gt;
Arguments file, fix_imports, encoding, errors, strict and buffers have the same meaning as in the Unpickler constructor.&amp;lt;/blockquote&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;pickle.loads(data, /, *, fix_imports=True, encoding=&amp;#039;ASCII&amp;#039;, errors=&amp;#039;strict&amp;#039;, buffers=None)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;blockquote&amp;gt;Return the reconstituted object hierarchy of the pickled representation data of an object. data must be a bytes-like object.&lt;br /&gt;
&lt;br /&gt;
The protocol version of the pickle is detected automatically, so no protocol argument is needed. Bytes past the pickled representation of the object are ignored.&lt;br /&gt;
&lt;br /&gt;
Arguments fix_imports, encoding, errors, strict and buffers have the same meaning as in the Unpickler constructor.&amp;lt;/blockquote&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;import pickle&lt;br /&gt;
import numpy as np&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class Example:&lt;br /&gt;
    a: int&lt;br /&gt;
    b: float&lt;br /&gt;
    c: np.ndarray&lt;br /&gt;
&lt;br /&gt;
    def __init__(self) -&amp;gt; None:&lt;br /&gt;
        super().__init__()&lt;br /&gt;
        self.a = 0&lt;br /&gt;
        self.b = 0&lt;br /&gt;
        self.c = np.zeros((1, 2))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
with open(&amp;quot;test.pkl&amp;quot;, &amp;quot;rb&amp;quot;) as file:&lt;br /&gt;
    instance_to_load = pickle.load(file)&lt;br /&gt;
&lt;br /&gt;
print(instance_to_load.a)  # -&amp;gt; 1&lt;br /&gt;
print(instance_to_load.b)  # -&amp;gt; 2&lt;br /&gt;
print(instance_to_load.c)  # -&amp;gt; [[3. 4.]]&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Davrot</name></author>
	</entry>
</feed>