Skip to content

Commit

Permalink
new magic command to load and run
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoMF committed Aug 4, 2023
1 parent 1fcf440 commit 7814397
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion gepetuto/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DoNotLoadMagics(Magics):
force_load = False

@line_magic
def do_not_load(self, line):
def do_not_load_snippet(self, line):
"""Magic command to hide the snippet and let the student code by themself."""
if DoNotLoadMagics.force_load:
get_ipython().run_line_magic("load", line) # noqa: F821
Expand All @@ -24,6 +24,12 @@ def force_load(self, line):
DoNotLoadMagics.force_load = False
print("Force load is OFF")

@line_magic
def load_snippet(self, line):
"""Magic command to load and run the snippet, this only work on JupyterLab."""
get_ipython().run_line_magic("run", "-i " + line)
get_ipython().run_line_magic("load", line)


ip = get_ipython() # noqa: F821
ip.register_magics(DoNotLoadMagics)
Expand Down

0 comments on commit 7814397

Please sign in to comment.