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.Fri, 12 Dec 2014 01:25:41 +0100Problem when reading filehttps://ask.sagemath.org/question/24985/problem-when-reading-file/Hi,
I am new to sage and there is a simple thing that does not work. I am working in GAP using the Sage notebook. I uploaded a file, called test.txt. Now, I want to run it into my worksheet. I select GAP, then run
Read("DATA+'test.txt'");
m1:=[[E(3),0],[0,E(3)^2]];
m:=Group(m1);
Supfast(m,[m1]);
Where Supfast is a function defined in test.txt. I know that the program works because it works when I just copy/paste the code in test.txt. But it does not work when I want to read the file. What is the problem? Thanks in advance!Mon, 24 Nov 2014 21:44:48 +0100https://ask.sagemath.org/question/24985/problem-when-reading-file/Answer by kcrisman for <p>Hi, </p>
<p>I am new to sage and there is a simple thing that does not work. I am working in GAP using the Sage notebook. I uploaded a file, called test.txt. Now, I want to run it into my worksheet. I select GAP, then run </p>
<p>Read("DATA+'test.txt'");
m1:=[[E(3),0],[0,E(3)^2]];
m:=Group(m1);
Supfast(m,[m1]);</p>
<p>Where Supfast is a function defined in test.txt. I know that the program works because it works when I just copy/paste the code in test.txt. But it does not work when I want to read the file. What is the problem? Thanks in advance!</p>
https://ask.sagemath.org/question/24985/problem-when-reading-file/?answer=24986#post-id-24986Hmm, I bet that only Sage and Python know about the DATA variable in the notebook. A workaround is to simply print out the value of `DATA` in a Sage cell and then cut and paste that.
I tried it, but then ran into a problem of Gap in the notebook not taking very long lines!
Read("/home//notebook/sage_notebook.sagenb/home/kcrisman/5/data/test.txt");
RuntimeError: Gap produced error output
Syntax error: ; expected in ... test.txt line 2
That one I recall but I can't remember if there was a workaround.Mon, 24 Nov 2014 22:09:11 +0100https://ask.sagemath.org/question/24985/problem-when-reading-file/?answer=24986#post-id-24986Answer by Dima for <p>Hi, </p>
<p>I am new to sage and there is a simple thing that does not work. I am working in GAP using the Sage notebook. I uploaded a file, called test.txt. Now, I want to run it into my worksheet. I select GAP, then run </p>
<p>Read("DATA+'test.txt'");
m1:=[[E(3),0],[0,E(3)^2]];
m:=Group(m1);
Supfast(m,[m1]);</p>
<p>Where Supfast is a function defined in test.txt. I know that the program works because it works when I just copy/paste the code in test.txt. But it does not work when I want to read the file. What is the problem? Thanks in advance!</p>
https://ask.sagemath.org/question/24985/problem-when-reading-file/?answer=25068#post-id-25068Indeed, GAP is not Python, and '+' does not work for concatenating strings in GAP.
It has a function that does concatenation:
`gap> Concatenation("bla","foo");`
`"blafoo"`Mon, 01 Dec 2014 15:02:15 +0100https://ask.sagemath.org/question/24985/problem-when-reading-file/?answer=25068#post-id-25068Comment by Dima for <p>Indeed, GAP is not Python, and '+' does not work for concatenating strings in GAP.
It has a function that does concatenation:</p>
<p><code>gap> Concatenation("bla","foo");</code></p>
<p><code>"blafoo"</code></p>
https://ask.sagemath.org/question/24985/problem-when-reading-file/?comment=25232#post-id-25232You can execute arbitrary GAP commands from Sage by using `gap.eval()`.
(or `libgap.eval()`, which would interact with a different GAP process).Fri, 12 Dec 2014 01:25:41 +0100https://ask.sagemath.org/question/24985/problem-when-reading-file/?comment=25232#post-id-25232Comment by kcrisman for <p>Indeed, GAP is not Python, and '+' does not work for concatenating strings in GAP.
It has a function that does concatenation:</p>
<p><code>gap> Concatenation("bla","foo");</code></p>
<p><code>"blafoo"</code></p>
https://ask.sagemath.org/question/24985/problem-when-reading-file/?comment=25205#post-id-25205Hmm, but `DATA` *is* set in the notebook already - in Python. How would GAP find it? (I mean, what syntax?)Wed, 10 Dec 2014 14:51:12 +0100https://ask.sagemath.org/question/24985/problem-when-reading-file/?comment=25205#post-id-25205Comment by kcrisman for <p>Indeed, GAP is not Python, and '+' does not work for concatenating strings in GAP.
It has a function that does concatenation:</p>
<p><code>gap> Concatenation("bla","foo");</code></p>
<p><code>"blafoo"</code></p>
https://ask.sagemath.org/question/24985/problem-when-reading-file/?comment=25081#post-id-25081Good to know! But would it recognize `DATA` in any case?Tue, 02 Dec 2014 14:51:47 +0100https://ask.sagemath.org/question/24985/problem-when-reading-file/?comment=25081#post-id-25081Comment by Dima for <p>Indeed, GAP is not Python, and '+' does not work for concatenating strings in GAP.
It has a function that does concatenation:</p>
<p><code>gap> Concatenation("bla","foo");</code></p>
<p><code>"blafoo"</code></p>
https://ask.sagemath.org/question/24985/problem-when-reading-file/?comment=25193#post-id-25193if DATA was set to something like "mydir/" then yes...Wed, 10 Dec 2014 10:07:59 +0100https://ask.sagemath.org/question/24985/problem-when-reading-file/?comment=25193#post-id-25193