Function Serialization

Mike Tammerman mtammerman at gmail.com
Wed Jun 1 08:02:46 EDT 2005


I want to serialize a function using its pointer. For example

>>> s = """
... def square(number):
...     return number**2
... """
>>> functions = {}
>>> exec s in functions
>>> f = functions['square']
>>> f
<function square at 0xb7b5d10c>

Then,
1. Serialize f,
2. Store it into a file a db.

One day later,
3. Retrieve from file or db,
4. Unserialize it
5. Use as it is a normal function, maybe I would set it to an object
with setattr

Any help will be very useful.

Mike




More information about the Python-list mailing list