Skip to content

Instantly share code, notes, and snippets.

@roman-smirnov
Created December 26, 2019 08:44
Show Gist options
  • Save roman-smirnov/a9d2432594c3364c17fd7d980e354f4f to your computer and use it in GitHub Desktop.
Save roman-smirnov/a9d2432594c3364c17fd7d980e354f4f to your computer and use it in GitHub Desktop.
Limit code scope to current cell in Jupyter Notebook
from IPython.core.magic import register_cell_magic
@register_cell_magic
def cellscope(line, cell): exec(cell)
## Example (in a code cell):
# %%cellscope
# x = 'hello' # x is local to current code cell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment