Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Check if code is running in SageMath Cell or Jupyter notebook

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
else:
    auto = UpdateButton(text="Press to update")
@interact
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?