Ask Your Question

How to read and run commands from a text file?

asked 2018-10-26 15:01:18 -0500

Leon gravatar image

I have all my commands in a text file, and I would just like to run them in Sage. What is the easiest way to do this?

For example, in sage.txt, I have written:


The command with open('/home/sage.txt','r') as ll: bdrs=[sage_eval(l.strip()) for l in ll]; returns

File "<string>", line 1
SyntaxError: invalid syntax

Also, does Sage have a limit on how much RAM it can use? If yes, how can I increase the available memory?

edit retag flag offensive close merge delete



The error in your code is that sage_eval evaluates expressions and not arbitrary statements such as assignments (the ^ is pointing at the equals sign).

rburing gravatar imagerburing ( 2018-10-27 04:00:36 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-10-26 15:13:45 -0500

slelievre gravatar image

The problem is with the file extension.

Use the file extension .sage.

For example, call your file something.sage.

Then type

sage: load('something.sage')

and check that your matrices have been defined correctly.

sage: d0
[1 0 0 0]
[0 1 1 0]
[1 0 0 0]
[0 1 1 0]
sage: d1
[ 0  0  0  0]
[-1  0  1  0]
[-1  0  1  0]
[ 0 -1  0  1]
edit flag offensive delete link more


Great, it works! Could you also please answer the question about RAM, before I accept?

Leon gravatar imageLeon ( 2018-10-26 15:54:42 -0500 )edit

I think Sage can use as much RAM as you have available, no special thing to do.

For some of the software used by Sage, there is a setting to how much memory they are allocated by default when used from Sage, and there are special commands to set that memory amount to some other value than the default.

For GAP and libGAP, use set_gap_memory_pool_size; see this 2018-09 sage-devel thread.

For PARI/GP, there might be something about parisize, parisizemax, primelimit.

For other systems, there might be some indication in the dedicated pages to the interface to each of them... See documentation on interfaces.

Do you have a specific use case in mind?

slelievre gravatar imageslelievre ( 2018-10-26 17:59:06 -0500 )edit

Yes, I'll be computing a lot of homology of chain complexes. Thank you for your answers!!

Leon gravatar imageLeon ( 2018-10-27 03:45:15 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2018-10-26 13:24:48 -0500

Seen: 143 times

Last updated: Oct 26 '18