human
Complete the below
def enable_automatic_symbols(app):

    ''''Allow IPython to automatially create symbols (``isympy -a``).'
    '''

Write me a the Python code you requested?
assistant
#Here is the Python code you requested.
    import re
    re_nameerror = re.compile("name    '(?P<symbol>[A-Za-z_][A-Za-z0-9_]*)'    is    not    defined")
    def _handler(self, etype, value, tb, tb_offset=None):
        'Handle    :exc:`NameError`    exception    and    allow    injection    of    missing    symbols.    '
        if ((etype is NameError) and tb.tb_next and (not tb.tb_next.tb_next)):
            match = re_nameerror.match(str(value))
            if (match is not None):
                self.run_cell(("%(symbol)s    =    Symbol('%(symbol)s')" % {'symbol': match.group('symbol')}), store_history=False)
                try:
                    code = self.user_ns['In'][(-1)]
                except (KeyError, IndexError):
                    pass
                else:
                    self.run_cell(code, store_history=False)
                    return None
                finally:
                    self.run_cell(('del    %s' % match.group('symbol')), store_history=False)
        stb = self.InteractiveTB.structured_traceback(etype, value, tb, tb_offset=tb_offset)
        self._showtraceback(etype, value, stb)
    if hasattr(app, 'shell'):
        app.shell.set_custom_exc((NameError,), _handler)
    else:
        app.set_custom_exc((NameError,), _handler)