##// END OF EJS Templates
Jorgen's %clean array
vivainio -
Show More
@@ -1,35 +1,46 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """ IPython extension: add %clear magic """
2 """ IPython extension: add %clear magic """
3
3
4 import IPython.ipapi
4 import IPython.ipapi
5 ip = IPython.ipapi.get()
5 import gc
6
6 ip = IPython.ipapi.get()
7
7
8 def clear_f(self,arg):
8
9 """ Clear various data (e.g. stored history data)
9 def clear_f(self,arg):
10
10 """ Clear various data (e.g. stored history data)
11 %clear out - clear output history
11
12 %clear in - clear input history
12 %clear out - clear output history
13 """
13 %clear in - clear input history
14
14 """
15 api = self.getapi()
15
16 for target in arg.split():
16 api = self.getapi()
17 if target == 'out':
17 for target in arg.split():
18 print "Flushing output cache (%d entries)" % len(api.user_ns()['_oh'])
18 if target == 'out':
19 self.outputcache.flush()
19 print "Flushing output cache (%d entries)" % len(api.user_ns()['_oh'])
20 elif target == 'in':
20 self.outputcache.flush()
21 print "Flushing input history"
21 elif target == 'in':
22 from IPython import iplib
22 print "Flushing input history"
23 del self.input_hist[:]
23 from IPython import iplib
24 del self.input_hist_raw[:]
24 del self.input_hist[:]
25 for n in range(1,self.outputcache.prompt_count + 1):
25 del self.input_hist_raw[:]
26 key = '_i'+`n`
26 for n in range(1,self.outputcache.prompt_count + 1):
27 try:
27 key = '_i'+`n`
28 del self.user_ns[key]
28 try:
29 except: pass
29 del self.user_ns[key]
30
30 except: pass
31 ip.expose_magic("clear",clear_f)
31 elif target == 'array':
32
32 try:
33
33 pylab=ip.IP.pylab
34
34 for x in self.user_ns.keys():
35
35 if isinstance(self.user_ns[x],pylab.arraytype):
36 del self.user_ns[x]
37 except AttributeError:
38 print "Clear array only available in -pylab mode"
39 gc.collect()
40
41
42 ip.expose_magic("clear",clear_f)
43
44
45
46
@@ -2,7 +2,7 b''
2 """
2 """
3 Classes for handling input/output prompts.
3 Classes for handling input/output prompts.
4
4
5 $Id: Prompts.py 1261 2006-04-11 14:37:02Z vivainio $"""
5 $Id: Prompts.py 1264 2006-04-11 19:24:29Z vivainio $"""
6
6
7 #*****************************************************************************
7 #*****************************************************************************
8 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
8 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
@@ -442,7 +442,6 b' class CachedOutput:'
442 # Store the last prompt string each time, we need it for aligning
442 # Store the last prompt string each time, we need it for aligning
443 # continuation and auto-rewrite prompts
443 # continuation and auto-rewrite prompts
444 self.last_prompt = ''
444 self.last_prompt = ''
445 self.entries = [None] # output counter starts at 1 for the user
446 self.Pprint = Pprint
445 self.Pprint = Pprint
447 self.output_sep = output_sep
446 self.output_sep = output_sep
448 self.output_sep2 = output_sep2
447 self.output_sep2 = output_sep2
@@ -563,9 +562,8 b' class CachedOutput:'
563 # hackish access to top-level namespace to create _1,_2... dynamically
562 # hackish access to top-level namespace to create _1,_2... dynamically
564 to_main = {}
563 to_main = {}
565 if self.do_full_cache:
564 if self.do_full_cache:
566 self.entries.append(arg)
567 new_result = '_'+`self.prompt_count`
565 new_result = '_'+`self.prompt_count`
568 to_main[new_result] = self.entries[-1]
566 to_main[new_result] = arg
569 self.user_ns.update(to_main)
567 self.user_ns.update(to_main)
570 self.user_ns['_oh'][self.prompt_count] = arg
568 self.user_ns['_oh'][self.prompt_count] = arg
571
569
General Comments 0
You need to be logged in to leave comments. Login now