Function Serialization

Michele Simionato michele.simionato at gmail.com
Wed Jun 1 14:30:23 CEST 2005


The simple way is to use shelve:

$ ipython
Python 2.4.1c2 (#2, Mar 19 2005, 01:04:19)
Type "copyright", "credits" or "license" for more information.

IPython 0.6.5 -- An enhanced Interactive Python.
?       -> Introduction to IPython's features.
%magic  -> Information about IPython's 'magic' % functions.
help    -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

In [1]: import shelve

In [2]: sh=shelve.open("x.shelve")

In [3]: def f(): pass
   ...:

In [4]: sh["f"]=f

In [5]: sh.close()

In [6]: sh=shelve.open("x.shelve")

In [7]: sh["f"]
Out[7]: <function f at 0xb7d5f614>

You may want to experiment a bit.

                     Michele Simionato




More information about the Python-list mailing list