Ask Your Question
0

save and load in SAGE

asked 2014-11-23 14:46:13 +0100

anonymous user

Anonymous

Hello.

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

For example...

At first, I make file.sage file.

a=1
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
1

answered 2014-11-23 15:07:31 +0100

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')
out.write(str(L))
out.close()
edit flag offensive delete link more

Comments

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

Semin gravatar imageSemin ( 2014-11-24 02:37:27 +0100 )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

Stats

Asked: 2014-11-23 14:46:13 +0100

Seen: 985 times

Last updated: Nov 23 '14