On 8/10/07, mak <[EMAIL PROTECTED]> wrote:
>
> I'm puzzled by the logic behind loading files:
>
> I have a file called 'con.sage' (which contains a simple assignment of
> a sequence to a variable) saved in the directory from which I run
> sage. In the notebook, I type
>
> load 'con.sage'
>
> and it loads no problem. I want, however, for the file to load in the
> course of executing a function, so I put something like
You should not do that -- or, at least loading in the body of a function
isn't currently supported. Roughly what's in con.sage? I'm sure there's
another way to do this particular thing rather than using load.
>
> def blah():
> ...
> load 'con.sage'
>
> It reports a syntax error -- it seems to want the file name
> parenthesized:'
> def blahj():
> load('con.sage')
>
> That's accepted, but when I try to run blah(), I get
>
>
> Exception (click to the left for traceback):
> ...
> IOError: [Errno 2] No such file or directory: '/home/mak/mixed/
> sage_notebook/objects/con.sage.sobj'
load('...') with parenthesis is a SAGE function that loads a saved sobj.
load '...'
is a notebook or command line command which loads the given
file and exec's it immediately.
> which baffles me on two counts: why does it look for the file in a
> different directory (sage is running from home/mak/mixed), and why
> does it want to tack on a .sobj? Should I save my (pari-generated)
> file with a .sobj extension.
If con.sage is just the output of PARI and can be interpreted by
SAGE, e.g., if con.sage were:
a = matrix(2,[1,2,3,4])
then you could replace con.sage by con.data with contents
matrix(2,[1,2,3,4])
then do the following in your program:
a = sage_eval( open('con.data').read() )
The open('con.data').read() command opens the given file and reads its
contents into a string. The sage_eval command evaluates the resulting
data using SAGE and returns the result.
-- William
--~--~---------~--~----~------------~-------~--~----~
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-support
URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/
-~----------~----~----~----~------~----~------~--~---