Re: Function Serialization

2005-06-01 Thread Lonnie Princehouse
By default, shelve uses pickle to serialize objects.Pickle doesn't actually serialize functions... it just saves the function's name and name of its defining module, and upon loading attempts to find that function again. This is pretty much /never/ going to work the way you want it to if you'r

Re: Function Serialization

2005-06-01 Thread Mike Tammerman
Michele, thank you for the suggestion, it works as you mention. But in my case the function is inside a string and I should exec the string to get the function. Something like this >>> fields = {} >>> s = 'def f(): pass' >>> exec s in fields >>> f = fields['f'] >>> f >>> import shelve >>> d = sh

Re: Function Serialization

2005-06-01 Thread Michele Simionato
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' % fun

Function Serialization

2005-06-01 Thread Mike Tammerman
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 Then, 1. Serialize f, 2. Store it into a file a db. One day later, 3. Retrieve from fil