<jupyter_start><jupyter_text>So, from last week, we have a cell magic that reads the line and the cell, and outputs the result of evaluating the line, and parsing the cell:<jupyter_code>%%mycell 1 + 3
the_value = 1337
print(the_value)
import ast
print(ast.dump(_2[1], indent=2))
the_cell_ast = _2[1]
exec(compile(the_cell_ast, '<my-cell-magic>', 'exec'))
the_value
import this<jupyter_output>The Zen of Python, by <NAME>

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!<jupyter_text>Quick Tip`parse()` will throw an exception when given empty input.<jupyter_code>ast.parse('', mode='eval')
%reload_ext metamagics
%%mycell
1996<jupyter_output><empty_output><jupyter_text>We didn't have a _side effect_ in the cell, so there was no output, or change in our environment. The Challenge is AfootQuick quiz: how can I get a cell magic function from the line input to the cell metamagic?<jupyter_code>%%mycell a_foot
def a_foot(cell):
    print(f'{cell} is {"not" if cell.startswith("12" else "")} a foot.')

%%mycell 1 + 11
def a_foot(cell):
    print(f'{cell} is {"not" if cell.startswith("12") else ""} a foot.')

%%mycell a_foot
12<jupyter_output><empty_output><jupyter_text>Fail!We don't "see" the Notebook environment that has the `a_foot()` function, so let's extend the environment explicitly in `metamagics.py`...<jupyter_code>%reload_ext metamagics
%%mycell 1 + 11
def a_foot(cell):
    print(f'{cell} is {"not" if cell.startswith("12") else ""} a foot.')

%%mycell a_foot
print('What is going on here?')
%reload_ext metamagics
%%mycell 1 + 11
def a_foot(cell):
    print(f'{cell} is {"" if cell.startswith("12") else "not "}a foot.')

%%mycell a_foot
12 inches...
%%mycell
def ouroboros(cell):
    cell_ast = parse(cell, mode='exec')
    cell_co = compile(cell_ast, '<ouroboros-cell>', 'exec')
    exec(cell_co)

%%mycell ouroboros
print('It worked!!!')<jupyter_output>It worked!!!
{'fraction_non_alphanumeric': 0.10977443609022557, 'fraction_numerical': 0.013533834586466165, 'mean_word_length': 5.145496535796767, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '158280', 'license': 'MIT', 'n_tokens_mistral': 912, 'n_tokens_neox': 861, 'n_words': 340, 'path': 'ohop/MetaMagicsPlay-ChallengeAccepted.ipynb', 'repo_name': 'gitter-badger/ohop', 'size': '2664'}