Created
April 11, 2018 10:01
-
-
Save korakot/a3f12629efef2e38f1abbec9924245b5 to your computer and use it in GitHub Desktop.
Create a new cell magic in Jupyter (and Colab)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from IPython.display import HTML | |
from IPython.core.magic import register_cell_magic | |
# equivalent to %%js | |
@register_cell_magic | |
def myjs(line, cell): | |
return HTML(f''' | |
<script> | |
{cell} | |
</script> | |
''') | |
# assign cell content to a variable too | |
@register_cell_magic | |
def var(line, cell): | |
name = line.split()[0] | |
globals()[name] = cell | |
return cell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment