def del_var(self, varname, by_name=False):
if varname in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>raise ValueError("<STR_LIT>" % varname)<EOL><DEDENT>ns_refs = self.all_ns_refs<EOL>if by_name:                    <EOL><INDENT>for ns in ns_refs:<EOL><INDENT>try:<EOL><INDENT>del ns[varname]<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>else:                         <EOL><INDENT>try:<EOL><INDENT>obj = self.user_ns[varname]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise NameError("<STR_LIT>" % varname)<EOL><DEDENT>ns_refs.append(self.history_manager.output_hist)<EOL>for ns in ns_refs:<EOL><INDENT>to_delete = [n for n, o in ns.items() if o is obj]<EOL>for name in to_delete:<EOL><INDENT>del ns[name]<EOL><DEDENT><DEDENT>for name in ('<STR_LIT:_>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>if getattr(self.displayhook, name) is obj:<EOL><INDENT>setattr(self.displayhook, name, None)<EOL><DEDENT><DEDENT><DEDENT>
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.