Package sage :: Package structure :: Module sage_object
[hide private]
[frames] | no frames]

Module sage_object



File: sage/structure/sage_object.pyx (starting at line 1)

Abstract base class for SAGE objects



Classes [hide private]
  SageObject
Functions [hide private]
 
dumps(...)
File: sage/structure/sage_object.pyx (starting at line 513) dumps(obj): Dump obj to a string s.
 
load(...)
File: sage/structure/sage_object.pyx (starting at line 416) load(filename): Load \sage object from the file with name filename, which will have an .sobj extension added if it doesn't have one.
 
loads(...)
File: sage/structure/sage_object.pyx (starting at line 537) Recover an object x that has been dumped to a string s using s = dumps(x).
 
picklejar(...)
File: sage/structure/sage_object.pyx (starting at line 590) Create pickled sobj of obj in dir, with name the absolute value of the hash of the pickle of obj.
 
save(...)
File: sage/structure/sage_object.pyx (starting at line 471) save(obj, filename=None): Save obj to the file with name filename, which will have an .sobj extension added if it doesn't have one.
 
unpickle_all(...)
File: sage/structure/sage_object.pyx (starting at line 641) Unpickle all sobj's in the given directory, reporting failures as they occur.
Variables [hide private]
  base = ['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8...
Function Details [hide private]

dumps(...)

 
File: sage/structure/sage_object.pyx (starting at line 513)

dumps(obj):

Dump obj to a string s.  To recover obj, use loads(s).

EXAMPLES:
    sage: a = 2/3
    sage: s = dumps(a)
    sage: print len(s)
    49
    sage: loads(s)
    2/3    

load(...)

 
File: sage/structure/sage_object.pyx (starting at line 416)

load(filename):

Load \sage object from the file with name filename, which will
have an .sobj extension added if it doesn't have one.

NOTE: There is also a special SAGE command (that is not
available in Python) called load that you use by typing

            sage: load filename.sage           # not tested
            
The documentation below is not for that command.  The documentation
for load is almost identical to that for attach.  Type attach? for
help on attach.

This also loads a ".sobj" file over a network by specifying the full URL.
(Setting "verbose = False" suppresses the loading progress indicator.)    

EXAMPLE:
    sage: u = 'http://sage.math.washington.edu/home/was/db/test.sobj'  # optional
    sage: s = load(u)                                                  # optional
    Attempting to load remote file: http://sage.math.washington.edu/home/was/db/test.sobj
    Loading: [.]        
    sage: s                                                            # optional
    'hello SAGE'

loads(...)

 
File: sage/structure/sage_object.pyx (starting at line 537)

Recover an object x that has been dumped to a string s
using s = dumps(x).

EXAMPLES:
    sage: a = matrix(2, [1,2,3,-4/3])
    sage: s = dumps(a)
    sage: loads(s)
    [   1    2]
    [   3 -4/3]

One can load uncompressed data even if one messes up
and doesn't specify compress=False.  This is slightly
slower though.
    sage: v = [1..10]
    sage: loads(dumps(v, compress=False)) == v
    True
    sage: loads(dumps(v, compress=False), compress=True) == v
    True
    sage: loads(dumps(v, compress=True), compress=False) == v
    True

picklejar(...)

 
File: sage/structure/sage_object.pyx (starting at line 590)

Create pickled sobj of obj in dir, with name the absolute value of
the hash of the pickle of obj.  This is used in conjection with
sage.structure.sage_object.unpickle_all.

To use this to test the whole Sage library right now, set the
environment variable SAGE_PICKLE_JAR, which will make it so dumps
will by default call picklejar with the default dir.  Once you do
that and doctest Sage, you'll find that the given directory
contains a bunch of pickled objects along with corresponding txt
descriptions of them.  Use the
sage.structure.sage_object.unpickle_all to see if they unpickle
later.

INPUTS:
    obj -- a pickleable object
    dir -- a string or None; if None defaults to
           SAGE_ROOT/tmp/pickle_jar-version

EXAMPLES:
    sage: dir = tmp_dir()
    sage: sage.structure.sage_object.picklejar(1,dir)
    sage: len(os.listdir(dir))
    2

save(...)

 
File: sage/structure/sage_object.pyx (starting at line 471)

save(obj, filename=None):

Save obj to the file with name filename, which will 
have an .sobj extension added if it doesn't have one.
This will \emph{replace} the contents of filename.

EXAMPLES:
    sage: a = matrix(2, [1,2,3,-5/2])
    sage: save(a, 'test.sobj')
    sage: load('test')
    [   1    2]
    [   3 -5/2]
    sage: E = EllipticCurve([-1,0])
    sage: P = plot(E)
    sage: save(P, 'test')
    sage: save(P, filename="sage.png", xmin=-2)
    sage: print load('test.sobj')
    Graphics object consisting of 2 graphics primitives
    sage: save("A python string", './test')
    sage: load('./test.sobj')
    'A python string'
    sage: load('./test')
    'A python string'

unpickle_all(...)

 
File: sage/structure/sage_object.pyx (starting at line 641)

Unpickle all sobj's in the given directory, reporting failures as
they occur.  Also printed the number of successes and failure.

INPUT:
    dir -- string; a directory

EXAMPLES:
    sage: dir = tmp_dir()
    sage: sage.structure.sage_object.picklejar('hello', dir)
    sage: sage.structure.sage_object.unpickle_all(dir)
    Successfully unpickled 1 objects.
    Failed to unpickle 0 objects.


Variables Details [hide private]

base

Value:
['4ti2-20061025',
 'R-2.6.0',
 'atlas-3.7.37',
 'atlas-3.8.1',
 'atlas-3.8.1.p1',
 'atlas-3.8.1.p3',
 'atlas-3.8.p11',
 'atlas-3.8.p6',
...