1
2 """ IPython
3
4 Classes that help interacting with IPython
5 """
6
7 import base64
8 from IPython.display import Javascript, display
9 from IPython.utils.py3compat import str_to_bytes, bytes_to_str
10
12 """Create a code cell in the IPython Notebook.
13
14 Found at https://github.com/ipython/ipython/issues/4983
15
16 Parameters
17 code: unicode
18 Code to fill the new code cell with.
19 where: unicode
20 Where to add the new code cell.
21 Possible values include:
22 at_bottom
23 above
24 below"""
25 encoded_code = bytes_to_str(base64.b64encode(str_to_bytes(code)))
26 display(Javascript("""
27 var code = IPython.notebook.insert_cell_{0}('code');
28 code.set_text(atob("{1}"));
29 """.format(where, encoded_code)))
30
34