Ask Your Question
1

How to find if computation is in a notebook or sage prompt ?

asked 2011-02-17 00:37:39 -0500

  • Example of what is needed in sage prompt:

    sage: is_sageprompt()

    True

  • Example of what is needed in a notebook:

In an input cell: is_sagenotebook()

The output cell: True

edit retag flag offensive close merge delete

Comments

Can you let us know how this would be useful? One of the things we like to do in Sage is make sure there is *not* a difference, so one can use either method, though things like @interact keep this from being 100% true.

kcrisman gravatar imagekcrisman ( 2011-02-17 01:54:51 -0500 )edit

I would like pretty print some results in both notebook and sage prompt. The comand html('

Big Table

') works fine in notebook but not in sage prompt. I will use html(...) in notebook and "print" in sage prompt.

Pedro Cruz gravatar imagePedro Cruz ( 2011-02-17 04:51:37 -0500 )edit

Then using this flag should work fine.

kcrisman gravatar imagekcrisman ( 2011-02-17 05:39:56 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
4

answered 2011-02-17 01:57:30 -0500

kcrisman gravatar image

There is an env variable of sorts called EMBEDDED_MODE, I think, which is used internally to tell whether one is in the notebook.

----------------------------------------------------------------------
| Sage Version 4.6.2.alpha1, Release Date: 2011-01-20                |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
**********************************************************************
*                                                                    *
* Warning: this is a prerelease version, and it may be unstable.     *
*                                                                    *
**********************************************************************
Loading Sage library. Current Mercurial branch is: plotpatches
sage: sage.plot.plot.EMBEDDED_MODE
False

But in the notebook this will give True.

edit flag offensive delete link more

Comments

Nice! It seems to me the natural place for some flag like that would be in notebook.*, which is where I looked for it.

DSM gravatar imageDSM ( 2011-02-17 02:15:58 -0500 )edit

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: 2011-02-17 00:37:39 -0500

Seen: 307 times

Last updated: Feb 17 '11