Ask Your Question

save and load in SAGE

asked 2014-11-23 07:46:13 -0500

anonymous user



In my case, I am using SAGE in my macbook.

For example...

At first, I make file.sage file.

def plus_one(number):
  return number+1

In terminal, I go to the folder which has file.sage and enter SAGE

And then I load file by using the below command.

sage: load("file.sage")

After some calculations, I make L.

sage: L=[]
sage: for i in range(10):
sage:   L=L+[a+plus_one(i)]

My question is how can I save L in some file like file.sage.

file.sage is editable in another editors, easily.

It is almost same as ordinary text file.

But if I use the command save(L, "file") then file.sobj file appears. I don't know how do I edit that file.

In that case, if I want to change value of before variables then... it is uncomfortable.

Is there any good way to save some datas?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-11-23 08:07:31 -0500

ndomes gravatar image

You want to save your list in a text file? Create a file object, write a string representation of the list.

More about reading and writing files see python documentation

L = range(20)
out = file('out.txt','w')
edit flag offensive delete link more


SAGE cannot load 'out.txt' file. But 'out.sage' is possible. Your answer is very helpful!!

Semin gravatar imageSemin ( 2014-11-23 19:37:27 -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: 2014-11-23 07:46:13 -0500

Seen: 165 times

Last updated: Nov 23 '14