On Oct 8, 2006, at 9:59 AM, Martin Albrecht wrote:
> On Sunday 08 October 2006 07:59, Justin C. Walker wrote:
>> 1) Although pickling is not supposed to work, in my case, it seems
>> to. I have a largish (~5MB) pickled file of one dict. I ran the
>> code in SAGE 1.4, and the file was correctly (?) unpickled. Is this
>> a surprise? The dictionary has strings as keys and (SAGE) integers
>> as values.
>
> My theory why this works: The only thing SAGE 1.4 broke was moving
> from Python
> 2.4 to 2.5 which could have changed the dicts but apparently they
> preserved
> pickling/"binary" compatibility. Same goes for strings. Also many
> Pyrex files
> have been moved around but that didn't break pickling the integers
> because I
> believe the Python function to unpickle the Integer might have been
> saved to
> the pickled file (?) and the string from which the Python function
> reconstructs the integer kept working as the Python guys seemed to
> have
> preserved pickling compatibility for them. The relevant code is here:
>
> cdef class Integer(sage.structure.element.EuclideanDomainElement):
>
> ...
>
> def __reduce__(self):
>
> ...
>
> return sage.rings.integer.make_integer, (self.str(32),)
>
> So you had a python function and a string in your file on harddisk
> which
> doesn't seem to present any problem to unpickling.
Thanks for the details; I wondered what the reduce stuff was for.
>> b) is there a way to have code that works both in SAGE 1.4 and
>> pre-1.4?
>
> The import changed:
> SAGE 1.3.x.x: no import of copy in devel/sage/sage/all.py
> SAGE 1.4: from copy import copy
Ah! That explains a lot.
Thanks!
Justin
--
Justin C. Walker, Curmudgeon-At-Large
Institute for the Absorption of Federal Funds
--------
Men are from Earth.
Women are from Earth.
Deal with it.
--------
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-forum
URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/
-~----------~----~----~----~------~----~------~--~---