Print input history (_i variables), with most recent last. By default, input history is printed without line numbers so it can be directly pasted into an editor. Use -n to show them. By default, all input history from the current session is displayed. Ranges of h
(self, parameter_s = '')
| 109 | @skip_doctest |
| 110 | @line_magic |
| 111 | def history(self, parameter_s = ''): |
| 112 | """Print input history (_i<n> variables), with most recent last. |
| 113 | |
| 114 | By default, input history is printed without line numbers so it can be |
| 115 | directly pasted into an editor. Use -n to show them. |
| 116 | |
| 117 | By default, all input history from the current session is displayed. |
| 118 | Ranges of history can be indicated using the syntax: |
| 119 | |
| 120 | ``4`` |
| 121 | Line 4, current session |
| 122 | ``4-6`` |
| 123 | Lines 4-6, current session |
| 124 | ``4-`` |
| 125 | Lines 4 onward (to end), current session |
| 126 | ``243/1-5`` |
| 127 | Lines 1-5, session 243 |
| 128 | ``~2/`` |
| 129 | All lines of session 2 before current |
| 130 | ``~4/4-`` |
| 131 | Lines 4 onward (to end), session 4 before current |
| 132 | ``~2/7`` |
| 133 | Line 7, session 2 before current |
| 134 | ``~8/1-~6/5`` |
| 135 | From the first line of 8 sessions ago, to the fifth line of 6 |
| 136 | sessions ago. |
| 137 | |
| 138 | Multiple ranges can be entered, separated by spaces |
| 139 | |
| 140 | The same syntax is used by %macro, %save, %edit, %rerun |
| 141 | |
| 142 | Examples |
| 143 | -------- |
| 144 | :: |
| 145 | |
| 146 | In [6]: %history -n 4-6 |
| 147 | 4:a = 12 |
| 148 | 5:print(a**2) |
| 149 | 6:%history -n 4-6 |
| 150 | |
| 151 | """ |
| 152 | |
| 153 | args = parse_argstring(self.history, parameter_s) |
| 154 | |
| 155 | # For brevity |
| 156 | history_manager = self.shell.history_manager |
| 157 | |
| 158 | def _format_lineno(session, line): |
| 159 | """Helper function to format line numbers properly.""" |
| 160 | if session in (0, history_manager.session_number): |
| 161 | return str(line) |
| 162 | return "%s/%s" % (session, line) |
| 163 | |
| 164 | # Check if output to specific file was requested. |
| 165 | outfname = args.filename |
| 166 | if not outfname: |
| 167 | outfile = sys.stdout # default |
| 168 | # We don't want to close stdout at the end! |
nothing calls this directly
no test coverage detected