Issue
Good Afternoon from Germany, everybody!
Google Colab and I seem to have divergent opinions on what is possible or not... I just want a way to access the contents of all other cells from within a cell.
My use case is, that I want to POST the contents of a current Colab Notebook to an external server for grading with minimal user interaction (just running the cell).
So my question is: Is there a way to access the code cells of a Colab NB programmatically?
I saw this answer for Jupyter NB, but it does not work in Google Colab as the Jupyter
JS-Variable is not available. The variable google.colab
seems to not provide the same functionality, or am I missing something?
Google Colab seems to sandbox each cell in its one iframe, so I cannot query the contents of other cells via JS:
%%js
document.getElementsByClassName('cell')
When run in a cell this just leads to an empty HTMLCollection, when run in the Developer Tools of my browser I get the correct results.
Am I missing something here? Is there a way to escape the sandbox or access the current NB contents within a Python cell?
Thanks in Advance for your help!
Solution
Sure, here's a complete example: https://colab.research.google.com/drive/1mXuyMsPEXFU4ik9EGLBiWUuNfztf7J6_
The key bit is this:
# Obtain the notebook JSON as a string
from google.colab import _message
notebook_json_string = _message.blocking_request('get_ipynb', request='', timeout_sec=5)
Reproducing the executed example from the notebook:
Answered By - Bob Smith
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.