[Python] Call another jupyter notebook, passing variables and receiving variables

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

  1. Stack

    Stack Membro Participativo

    Let say I have two jupyter notebook files called: main and sub

    Here are my needs:

    1. Call and run sub from main
    2. Each notebook has its own variables space. For example, if x=1 in main, but x=2 in sub unless exchange info
    3. I can pass certain variables to sub and retrieve certain variables from sub (not all) ← This is very important as I do not want variables to overlap and mess up the code

    I have been trying all days with GPT and Copilot looking for an effective solution but:

    1. Using %run -i% or IPython.get_ipython` will just share all variables between the two notebooks
    2. Using nbclients → both GPT and Copilot keep giving wrong answers (i.e. I still cannot pass and receive variables from sub to main)

    I know there is another solution is create a defined fucntion on .py file; however since my work at the moment is complex to convert from ipynb file to py file

    If anyone have any suggestions, I would really appreciate (a sample code would be x2 appreciate)

    Thank you!

    Continue reading...

Compartilhe esta Página