Ask Your Question
1

Problem when reading file

asked 2014-11-24 21:44:48 +0200

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 15:02:15 +0200

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 14:51:47 +0200 )edit

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

Dima gravatar imageDima ( 2014-12-10 10:07:59 +0200 )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 14:51:12 +0200 )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-12 01:25:41 +0200 )edit
0

answered 2014-11-24 22:09:11 +0200

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 21:44:48 +0200

Seen: 281 times

Last updated: Dec 01 '14