ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 24 Nov 2014 02:37:27 +0100save and load in SAGEhttps://ask.sagemath.org/question/24957/save-and-load-in-sage/ 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?
Sun, 23 Nov 2014 14:46:13 +0100https://ask.sagemath.org/question/24957/save-and-load-in-sage/Answer by ndomes for <p>Hello.</p>
<p>In my case, I am using SAGE in my macbook.</p>
<p>For example...</p>
<p>At first, I make <code>file.sage</code> file.</p>
<pre><code>a=1
def plus_one(number):
return number+1
</code></pre>
<p>In terminal, I go to the folder which has <code>file.sage</code> and enter SAGE</p>
<p>And then I load file by using the below command.</p>
<pre><code>sage: load("file.sage")
</code></pre>
<p>After some calculations, I make <code>L</code>.</p>
<pre><code>sage: L=[]
sage: for i in range(10):
sage: L=L+[a+plus_one(i)]
</code></pre>
<p>My question is how can I save <code>L</code> in some file like <code>file.sage</code>.</p>
<p><code>file.sage</code> is editable in another editors, easily.</p>
<p>It is almost same as ordinary text file.</p>
<p>But if I use the command <code>save(L, "file")</code> then <code>file.sobj</code> file appears. I don't know how do I edit that file.</p>
<p>In that case, if I want to change value of before variables then... it is uncomfortable.</p>
<p>Is there any good way to save some datas?</p>
https://ask.sagemath.org/question/24957/save-and-load-in-sage/?answer=24958#post-id-24958You 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](https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files)
L = range(20)
out = file('out.txt','w')
out.write(str(L))
out.close() Sun, 23 Nov 2014 15:07:31 +0100https://ask.sagemath.org/question/24957/save-and-load-in-sage/?answer=24958#post-id-24958Comment by Semin for <p>You want to save your list in a text file? Create a file object, write a string representation of the list.</p>
<p>More about reading and writing files see <a href="https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files">python documentation</a></p>
<pre><code>L = range(20)
out = file('out.txt','w')
out.write(str(L))
out.close()
</code></pre>
https://ask.sagemath.org/question/24957/save-and-load-in-sage/?comment=24964#post-id-24964SAGE cannot load 'out.txt' file. But 'out.sage' is possible. Your answer is very helpful!!Mon, 24 Nov 2014 02:37:27 +0100https://ask.sagemath.org/question/24957/save-and-load-in-sage/?comment=24964#post-id-24964