In [ ]:
try:
get_ipython
except:
import sys
def get_ipython():
class dummy(object):
def run_cell_magic(*args):
print "No IPython; therefore no magic!"
magic = run_cell_magic
return dummy()
In [2]:
def foo():
return 'bar'
In [3]:
%ls
Work out a scheme s.t. cell magics %%test do not get written to .py file
In [1]:
from IPython.core.magic import register_cell_magic
@register_cell_magic
def test(line,cell):
g = get_ipython().user_global_ns
code = get_ipython().input_transformer_manager.transform_cell(cell)
path = '?'
ec = '?'
ccode = compile(code,'<file: {0} cell {1}>'.format(path,ec),'exec')
v = eval(ccode,g)
return code
In [2]:
%%test
a = 3
b = 4
a+b
Out[2]:
In [ ]:
##test
In [7]:
%lsmagic
Out[7]:
In [4]:
#%%sh
#ls -l *
In [5]:
%%bash
ls -l
/bin/pwd
echo "foo bar"
In [6]:
## Test Section:
# this doesn't get imported
def bar():
return 'foo'
In [7]:
# neither does this:
In [8]:
def zap():
return
In [9]:
#foo
In [ ]: