-
Notifications
You must be signed in to change notification settings - Fork 7
/
magic_donotload.py
35 lines (25 loc) · 927 Bytes
/
magic_donotload.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from IPython.core.magic import Magics, line_magic, magics_class
@magics_class
class DoNotLoadMagics(Magics):
forceLoad = False
@line_magic
def do_not_load(self, line):
if DoNotLoadMagics.forceLoad:
get_ipython().run_line_magic("load", line)
@line_magic
def force_load(self, line):
if line == "" or line == "on" or line == "True" or line == "1":
DoNotLoadMagics.forceLoad = True
print("Force load in ON")
else:
DoNotLoadMagics.forceLoad = False
print("Force load is OFF")
ip = get_ipython()
ip.register_magics(DoNotLoadMagics)
def forceLoad(force=True):
DoNotLoadMagics.forceLoad = force
print(
"""NB: as for all the tutorials, a magic command %do_not_load is introduced """
"""to hide the solutions to some questions. Change it for %load if you want to see """
"""(and execute) the solution."""
)