diff --git a/IPython/Extensions/clearcmd.py b/IPython/Extensions/clearcmd.py index fd07f34..58eb193 100644 --- a/IPython/Extensions/clearcmd.py +++ b/IPython/Extensions/clearcmd.py @@ -1,35 +1,46 @@ -# -*- coding: utf-8 -*- -""" IPython extension: add %clear magic """ - -import IPython.ipapi -ip = IPython.ipapi.get() - - -def clear_f(self,arg): - """ Clear various data (e.g. stored history data) - - %clear out - clear output history - %clear in - clear input history - """ - - api = self.getapi() - for target in arg.split(): - if target == 'out': - print "Flushing output cache (%d entries)" % len(api.user_ns()['_oh']) - self.outputcache.flush() - elif target == 'in': - print "Flushing input history" - from IPython import iplib - del self.input_hist[:] - del self.input_hist_raw[:] - for n in range(1,self.outputcache.prompt_count + 1): - key = '_i'+`n` - try: - del self.user_ns[key] - except: pass - -ip.expose_magic("clear",clear_f) - - - - +# -*- coding: utf-8 -*- +""" IPython extension: add %clear magic """ + +import IPython.ipapi +import gc +ip = IPython.ipapi.get() + + +def clear_f(self,arg): + """ Clear various data (e.g. stored history data) + + %clear out - clear output history + %clear in - clear input history + """ + + api = self.getapi() + for target in arg.split(): + if target == 'out': + print "Flushing output cache (%d entries)" % len(api.user_ns()['_oh']) + self.outputcache.flush() + elif target == 'in': + print "Flushing input history" + from IPython import iplib + del self.input_hist[:] + del self.input_hist_raw[:] + for n in range(1,self.outputcache.prompt_count + 1): + key = '_i'+`n` + try: + del self.user_ns[key] + except: pass + elif target == 'array': + try: + pylab=ip.IP.pylab + for x in self.user_ns.keys(): + if isinstance(self.user_ns[x],pylab.arraytype): + del self.user_ns[x] + except AttributeError: + print "Clear array only available in -pylab mode" + gc.collect() + + +ip.expose_magic("clear",clear_f) + + + + diff --git a/IPython/Prompts.py b/IPython/Prompts.py index 891f578..884ff64 100644 --- a/IPython/Prompts.py +++ b/IPython/Prompts.py @@ -2,7 +2,7 @@ """ Classes for handling input/output prompts. -$Id: Prompts.py 1261 2006-04-11 14:37:02Z vivainio $""" +$Id: Prompts.py 1264 2006-04-11 19:24:29Z vivainio $""" #***************************************************************************** # Copyright (C) 2001-2006 Fernando Perez @@ -442,7 +442,6 @@ class CachedOutput: # Store the last prompt string each time, we need it for aligning # continuation and auto-rewrite prompts self.last_prompt = '' - self.entries = [None] # output counter starts at 1 for the user self.Pprint = Pprint self.output_sep = output_sep self.output_sep2 = output_sep2 @@ -563,9 +562,8 @@ class CachedOutput: # hackish access to top-level namespace to create _1,_2... dynamically to_main = {} if self.do_full_cache: - self.entries.append(arg) new_result = '_'+`self.prompt_count` - to_main[new_result] = self.entries[-1] + to_main[new_result] = arg self.user_ns.update(to_main) self.user_ns['_oh'][self.prompt_count] = arg