Domanda

Is there a way to run a script upon a new notebook creation? What I am trying to achieve is, whenever any user initiates a new notebook from the Ipython dashboard, I want the dashboard to preload the new notebook to run some scripts that will populate latest information from the system, without the user typing them.

È stato utile?

Soluzione

I just found a somewhat workaround from http://ipython.org/ipython-doc/dev/config/ipython.html

The solution is to add a custom script into the config parameter c.InteractiveShellApp.exec_files in the ipython_notebook_config.py:

    c.InteractiveShellApp.exec_files = [
        'my_python_code.py',
        'my_ipython_code.ipy'
    ]

This is not updating the new notebook with the latest information at the time of the notebook creation, but somewhat does what I was looking for: injecting custom commands into notebooks without users explicitly typing in "run custom_script.ipy".

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top