import pickle
qux = [1, None, ('ned', 0)]
my_object = {'foo': 'bar', 'baz': qux}
my_pickle = pickle.dumps(my_object)
print my_pickle
(dp0
S'foo'
p1
S'bar'
p2
sS'baz'
p3
(lp4
I1
aNa(S'ned'
p5
I0
tp6
as.
Then, later on another machine or in another session:
my_object = pickle.loads(my_pickle)
import subprocess
import pickle
class Dangerous(object):
def __reduce__(self):
# This particular payload works on OSX.
return (
subprocess.Popen,
(('say', 'You are having a very bad day.'),))
dangerous_pickle = pickle.dumps(Dangerous())
# Don't do it!
some_object = pickle.loads(dangerous_pickle)
Other serialization formats:
Bonus: they're compatible with other languages and they're human readable.
These formats and their associated deserializers have had a handful of problems over the years.
IANASR, this is not advice, it's an observation:
Table of contents | t |
---|---|
Exposé | ESC |
Autoscale | e |
Full screen slides | f |
Presenter view | p |
Source files | s |
Slide numbers | n |
Blank screen | b |
Notes | 2 |
Help | h |