On Sunday 08 October 2006 07:59, Justin C. Walker wrote:
> Hi, all,
>
> A couple of observations/questions from the switch, in SAGE, from
> Python 2.4 to 2.5:
>
> 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.

Just my five cents,
Martin

> 2) This is something I picked up from a guy at the gas station down
> the road, so it may not be the right way to things, but: I need to
> "copy" lists in my code (to avoid the "points to the same data"
> problem of assignment).  In the pre-1.4 code, I found that
>                L1 = copy.copy(L)
> does what I want.  This doesn't work in SAGE 1.4:
>
>     <type 'exceptions.AttributeError'>: 'function' object has no
> attribute 'copy'
>
> but
>                L1 = copy(L)
> does work.  My questions:
>   a) is this the right way to do this?

Yes.

>   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

Martin

-- 
name: Martin Albrecht
_pgp: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8EF0DC99
_www: http://www.informatik.uni-bremen.de/~malb
_icq: 177334829
_aim: martinralbrecht
_jab: [EMAIL PROTECTED]


--~--~---------~--~----~------------~-------~--~----~
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/
-~----------~----~----~----~------~----~------~--~---

Reply via email to