Ask Your Question
1

Problem when reading file

asked 2014-11-24 14:44:48 -0600

thelpt234 gravatar image

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!

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2014-12-01 08:02:15 -0600

Indeed, 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"

edit flag offensive delete link more

Comments

Good to know! But would it recognize DATA in any case?

kcrisman gravatar imagekcrisman ( 2014-12-02 07:51:47 -0600 )edit

if DATA was set to something like "mydir/" then yes...

Dima gravatar imageDima ( 2014-12-10 03:07:59 -0600 )edit

Hmm, but DATAis set in the notebook already - in Python. How would GAP find it? (I mean, what syntax?)

kcrisman gravatar imagekcrisman ( 2014-12-10 07:51:12 -0600 )edit

You can execute arbitrary GAP commands from Sage by using gap.eval(). (or libgap.eval(), which would interact with a different GAP process).

Dima gravatar imageDima ( 2014-12-11 18:25:41 -0600 )edit
0

answered 2014-11-24 15:09:11 -0600

kcrisman gravatar image

Hmm, 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.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2014-11-24 14:44:48 -0600

Seen: 71 times

Last updated: Dec 01 '14