Check if code is running in SageMath Cell or Jupyter notebook

asked 2019-11-25 13:48:00 +0200

Juanjo gravatar image

I am preparing interacts to be run either in a Jupyter notebook or in SageMath Cell. I would like to write code valid for both environments, taking into account the differences between them. For example, I have not seen a common way to change the default text in auto update buttons. The following code would work in both environments if I would know how to automatically set up the running_in_Jupyter boolean:

if running_in_Jupyter:
    auto = False
    auto = UpdateButton(text="Press to update")
def test(n=slider(0,20,1), auto_update=auto):
    print n
if running_in_Jupyter: 
    test.widget.children[-2].description="Press to update"

So, is there a simple test I could implement to detect where the code is running?

edit retag flag offensive close merge delete