-
Notifications
You must be signed in to change notification settings - Fork 24
/
magic_donotload.py
30 lines (24 loc) · 1003 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
from IPython.core import magic_arguments
from IPython.core.magic import line_magic, cell_magic, line_cell_magic, Magics, 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.''')