• About
  • Archive
  • RSS

code.dump();

pickling: converting a Python object into a byte stream

>>> stuff = {
...   'hello': 'world',
...   'numbers': range(3),
... }

>>> import pickle

>>> data = pickle.dumps(stuff)

>>> len(data)
63

>>> print data
(dp0
S'hello'
p1
S'world'
p2
sS'numbers'
p3
(lp4
I0
aI1
aI2
as.

>>> pickle.loads(data)
{'hello': 'world', 'numbers': [0, 1, 2]}

  • Posted by inky
  • Tags:
    • python
  • January 25, 2009, 11:48pm

  • Permalink
← Previous Post   Next Post →

About

A place for code snippets, keyboard shortcuts, dirty hacks and other fun tricks. Use at your own risk!

Members

  • inky
  • arood
  • beret
  • nosmo

Search

Colophon

A group tumblelog, originally by inky. Powered by Tumblr and themed by Bill Israel.