def del_var(self, varname, by_name=False):
    "Delete a variable from the various namespaces, so that, as\n        far as possible, we're not keeping any hidden references to it.\n\n        Parameters\n        ----------\n        varname : str\n            The name of the variable to delete.\n        by_name : bool\n            If True, delete variables with the given name in each\n            namespace. If False (default), find the variable in the user\n            namespace, and delete references to it.\n        "
    if (varname in ('__builtin__', '__builtins__')):
        raise ValueError(('Refusing to delete %s' % varname))
    ns_refs = self.all_ns_refs
    if by_name:
        for ns in ns_refs:
            try:
                del ns[varname]
            except KeyError:
                pass
    else:
        try:
            obj = self.user_ns[varname]
        except KeyError as e:
            raise NameError(("name '%s' is not defined" % varname)) from e
        ns_refs.append(self.history_manager.output_hist)
        for ns in ns_refs:
            to_delete = [n for (n, o) in ns.items() if (o is obj)]
            for name in to_delete:
                del ns[name]
        if (self.last_execution_result.result is obj):
            self.last_execution_result = None
        for name in ('_', '__', '___'):
            if (getattr(self.displayhook, name) is obj):
                setattr(self.displayhook, name, None)
Delete a variable from the various namespaces, so that, as
far as possible, we're not keeping any hidden references to it.

Parameters
----------
varname : str
    The name of the variable to delete.
by_name : bool
    If True, delete variables with the given name in each
    namespace. If False (default), find the variable in the user
    namespace, and delete references to it.
def del_var(self, varname, by_name=False):
    "Delete a variable from the various namespaces, so that, as\n        far as possible, we're not keeping any hidden references to it.\n\n        Parameters\n        ----------\n        varname : str\n            The name of the variable to delete.\n        by_name : bool\n            If True, delete variables with the given name in each\n            namespace. If False (default), find the variable in the user\n            namespace, and delete references to it.\n        "
    if (varname in ('__builtin__', '__builtins__')):
        raise ValueError(('Refusing to delete %s' % varname))
    ns_refs = self.all_ns_refs
    if by_name:
        for ns in ns_refs:
            try:
                del ns[varname]
            except KeyError:
                pass
    else:
        try:
            obj = self.user_ns[varname]
        except KeyError as e:
            raise NameError(("name '%s' is not defined" % varname)) from e
        ns_refs.append(self.history_manager.output_hist)
        for ns in ns_refs:
            to_delete = [n for (n, o) in ns.items() if (o is obj)]
            for name in to_delete:
                del ns[name]
        if (self.last_execution_result.result is obj):
            self.last_execution_result = None
        for name in ('_', '__', '___'):
            if (getattr(self.displayhook, name) is obj):
                setattr(self.displayhook, name, None)