Ask Your Question

flow control in sage notebooks?

asked 2019-04-14 14:00:24 -0500

stockh0lm gravatar image

I would love to insert a break or stop command into sage files, in order to absolutly stop further processing. The interpreter (?) should not die or exit, but rather pretent to be done with the notebook.

I looked through the sage reference and didnt find something similar. actually i didnt find anything on the whole flow control topic.

edit retag flag offensive close merge delete


You mentioned "sage files" so it's not clear: Do you mean like .sage scripts? Or a Jupyter notebook (that you're executing with "Run All Cells" or something)? In the latter case (which is nothing specific to Sage) there are several ways you could "pause" execution: Have a cell deliberate raise an exception. Put in a time.sleep() (if you just want a temporary delay), put in a call to input(), etc.

Iguananaut gravatar imageIguananaut ( 2019-04-15 08:42:59 -0500 )edit

i mean bla.sage scripts, that i execute like "sage bla.sage". Is that also called sage notebook? or is that something else?

stockh0lm gravatar imagestockh0lm ( 2019-04-15 08:48:39 -0500 )edit

A .sage script is just a script. Just code saved to a file line-by-line for convenience so that you don't have to manually re-enter it manually into an interactive prompt. A notebook is another beast entirely. Sage is just Python so anything you can do in Python you can do in a Sage script. What exactly are you trying to do and why? What does "Pretend to be done with the notebook" mean to you, if not exit?

Iguananaut gravatar imageIguananaut ( 2019-04-18 11:51:12 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2019-04-14 14:36:31 -0500

Emmanuel Charpentier gravatar image

As far as I can tell, there is no way to do this "cleanly" under program control : a notebook is not a way to program a system. However, there are a few things possible, at least in Jupyter notebooks (the old Sage notebook is unmaintained, unmaintainable and will die sooner or later : don't start new work with it, unless you need some specific feature such as multi-user access) :

* Go to a cell, and request evaluation of all cells above.

* Introduce a cell raising a runtime error (e.g. a syntax error, referencing an undefined variable, division by 0, und so weiter...)..

* Write a program. Notebook is a great way to jot down and test ideas quickly, not to polish up a paper.

For the latter, \LaTeX and Sagetex (or Pythontex (or org-babel)) are much more easy...

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

1 follower


Asked: 2019-04-14 14:00:24 -0500

Seen: 25 times

Last updated: Apr 14