Show More
@@ -1,38 +1,35 | |||||
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 | ip = IPython.ipapi.get() | |
6 |
|
6 | |||
7 | def clear_list(l): |
|
|||
8 | while l: |
|
|||
9 | l.pop() |
|
|||
10 |
|
7 | |||
11 | def clear_f(self,arg): |
|
8 | def clear_f(self,arg): | |
12 | """ Clear various data (e.g. stored history data) |
|
9 | """ Clear various data (e.g. stored history data) | |
13 |
|
10 | |||
14 | %clear out - clear output history |
|
11 | %clear out - clear output history | |
15 | %clear in - clear input history |
|
12 | %clear in - clear input history | |
16 | """ |
|
13 | """ | |
17 |
|
14 | |||
18 | api = self.getapi() |
|
15 | api = self.getapi() | |
19 | for target in arg.split(): |
|
16 | for target in arg.split(): | |
20 | if target == 'out': |
|
17 | if target == 'out': | |
21 | print "Flushing output cache (%d entries)" % len(api.user_ns()['_oh']) |
|
18 | print "Flushing output cache (%d entries)" % len(api.user_ns()['_oh']) | |
22 | self.outputcache.flush() |
|
19 | self.outputcache.flush() | |
23 | elif target == 'in': |
|
20 | elif target == 'in': | |
24 | print "Flushing input history" |
|
21 | print "Flushing input history" | |
25 | from IPython import iplib |
|
22 | from IPython import iplib | |
26 |
|
|
23 | del self.input_hist[:] | |
27 |
|
|
24 | del self.input_hist_raw[:] | |
28 | for n in range(1,self.outputcache.prompt_count + 1): |
|
25 | for n in range(1,self.outputcache.prompt_count + 1): | |
29 | key = '_i'+`n` |
|
26 | key = '_i'+`n` | |
30 | try: |
|
27 | try: | |
31 | del self.user_ns[key] |
|
28 | del self.user_ns[key] | |
32 | except: pass |
|
29 | except: pass | |
33 |
|
30 | |||
34 | ip.expose_magic("clear",clear_f) |
|
31 | ip.expose_magic("clear",clear_f) | |
35 |
|
32 | |||
36 |
|
33 | |||
37 |
|
34 | |||
38 |
|
35 |
General Comments 0
You need to be logged in to leave comments.
Login now