Saturday, 26 June 2021

Access other Cell Contents within cell (Colab)

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!



from Access other Cell Contents within cell (Colab)

No comments:

Post a Comment