[Python] Programmatically change cell in JupyterLab

Discussão em 'Python' iniciado por Stack, Fevereiro 26, 2025.

  1. Stack

    Stack Membro Participativo

    I'm looking for a way to programatically change the contents of a jupyterlab cell after it has been run as a way to "lock" it.

    For my specific use-case, my cell essentially looks like

    curr_id = get_curr_id()
    data = load_data(curr_id)


    When I run this, get_curr_id() accesses a database and finds the most recent added dataset. After the cell is run once I want to "lock" this id to the cell, so that even if new data is added to the database, this cell will still reference the original dataset it first saw. I thought the easiest way to do this would be to programatically replace "curr_id = get_curr_id()" with the returned curr_id, but am not sure how to proceed.

    As more context, the database I am pulling from has new entries added every ~30 min. My typical workflow is to run a cell like above and analyze it. Then ~30 min later copy that same cell and run it again to analyze the new data that came in. However, if I now go back to the first cell, re-running it will now load the newest data, instead of the original data it found.

    Solution: In any case, I found a solution using ipython, linked below

    Continue reading...

Compartilhe esta Página