Ask Your Question
1

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

asked 2011-02-17 07:37:39 +0200

Pedro gravatar image
  • 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 08:54:51 +0200 )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 gravatar imagePedro ( 2011-02-17 11:51:37 +0200 )edit

Then using this flag should work fine.

kcrisman gravatar imagekcrisman ( 2011-02-17 12:39:56 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
4

answered 2011-02-17 08:57:30 +0200

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 09:15:58 +0200 )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 07:37:39 +0200

Seen: 529 times

Last updated: Feb 17 '11