breathe / NotebookScripter

Expose ipython jupyter notebooks as callbable functions or running scripts
MIT License
26 stars 1 forks source link

Tee output to stdout #4

Open et2010 opened 5 years ago

et2010 commented 5 years ago

Hi, @breathe Could you please support this?

https://github.com/jupyter/nbconvert/issues/374

breathe commented 5 years ago

Hmm @et2010 possibly -- I'm assuming the main use case for something like this would be to see the cell output as the notebook is executed and not to have to wait until after the notebook has fully executed? Or would it suffice for your needs to print something from the cells after the execution of the notebook has completed?

The first is a bit more complicated to support as I'm currently delegating to executenb method from jupyter to execute the notebook -- but I think I see a way to hack in something to execute code after each cell executes — which could potentially provide a way way to print the output incrementally during execution.

How would this feature ideally work for your needs? Would you want to see the json for the output cell's printed to stdout -- ... or maybe if the output cell type is "text/plain" then print the contents as text and otherwise print the json for the output cell ...?

et2010 commented 5 years ago

Thank you for your reply!

Sorry, I forgot to mention that I was using the following snippet from the example:

# output_notebook.ipynb will be a notebook file along with the rendered output cells
module = run_notebook_in_jupyter("./Example.ipynb", a_useful_mode_switch="non_idiot_mode")("some_useful_value", save_output_notebook="output_notebook.ipynb")

In this case, there is no output at all. I can only check the output in the saved notebook file. I was running some machine learning scripts/notebooks on the cloud and need to check the output to see if it went smoothly.