Created
March 6, 2025 18:48
-
-
Save fomightez/978e1203a4ffbaba37e76efe6ba027af to your computer and use it in GitHub Desktop.
In relation to [this Jupyter Discourse post](https://discourse.jupyter.org/t/how-to-execute-notebook-in-different-namespace/33532?u=fomightez)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "id": "59fa37ab-7322-4689-b080-383811455164", | |
| "metadata": {}, | |
| "source": [ | |
| "This is in relation to [this Jupyter Discourse post](https://discourse.jupyter.org/t/how-to-execute-notebook-in-different-namespace/33532?u=fomightez)\n", | |
| "\n", | |
| "-----" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "id": "62d7330d-7fa7-4ced-8b64-9d456beed87b", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "y=100\n", | |
| "Stored 'y' (int)\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "x = 2\n", | |
| "\n", | |
| "y = 100\n", | |
| "print(f\"{y=}\")\n", | |
| "%store y" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "id": "7e12ac02-e53e-4dd9-9612-81128b76e1e1", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "y=100\n", | |
| "y=150\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%run -n nbb.ipynb" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 3, | |
| "id": "ef31ffcf-4324-43da-be94-6b9ecfa14556", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "y=150\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "print(f\"{y=}\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 4, | |
| "id": "ccc3cf19-d68a-4743-a3b2-7d3de0435e5a", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "y=100\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%store -r y \n", | |
| "print(f\"{y=}\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "id": "448124a0-c921-4b3a-b26f-409e4802947b", | |
| "metadata": {}, | |
| "source": [ | |
| "That restored `y` to what it was set at in `nba.ipynb`.\n", | |
| "\n", | |
| "My puzzle though...\n", | |
| "I don't get this comment in the original post `# it still update y regardless having this or not` because the restore does work.\n", | |
| "I think 9gagmem meant to say, \"However, I don't want to need to store and then restore it\", maybe? That they should be independent? \n", | |
| "In other words, I think the comment should have read, \"# notebook b running should not update y regardless having this store and restor or not`\", or something along that line?" | |
| ] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Python 3 (ipykernel)", | |
| "language": "python", | |
| "name": "python3" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 3 | |
| }, | |
| "file_extension": ".py", | |
| "mimetype": "text/x-python", | |
| "name": "python", | |
| "nbconvert_exporter": "python", | |
| "pygments_lexer": "ipython3", | |
| "version": "3.10.16" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 5 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment