##// END OF EJS Templates
Remove python 2 specific line.
Terry Davis -
Show More
@@ -1,39 +1,38 b''
1 1 #!/usr/bin/env python
2 2 """Extract a session from the IPython input history.
3 3
4 4 Usage:
5 5 ipython-get-history.py sessionnumber [outputfile]
6 6
7 7 If outputfile is not given, the relevant history is written to stdout. If
8 8 outputfile has a .py extension, the translated history (without IPython's
9 9 special syntax) will be extracted.
10 10
11 11 Example:
12 12 ./ipython-get-history.py 57 record.ipy
13 13
14 14
15 15 This script is a simple demonstration of HistoryAccessor. It should be possible
16 16 to build much more flexible and powerful tools to browse and pull from the
17 17 history database.
18 18 """
19 19 import sys
20 20
21 21 from IPython.core.history import HistoryAccessor
22 22
23 23 session_number = int(sys.argv[1])
24 24 if len(sys.argv) > 2:
25 25 dest = open(sys.argv[2], "w")
26 26 raw = not sys.argv[2].endswith('.py')
27 27 else:
28 28 dest = sys.stdout
29 29 raw = True
30 30
31 31 with dest:
32 32 dest.write("# coding: utf-8\n")
33 33
34 34 # Profiles other than 'default' can be specified here with a profile= argument:
35 35 hist = HistoryAccessor()
36 36
37 37 for session, lineno, cell in hist.get_range(session=session_number, raw=raw):
38 cell = cell.encode('utf-8') # This line is only needed on Python 2.
39 38 dest.write(cell + '\n')
General Comments 0
You need to be logged in to leave comments. Login now