MCPcopy Create free account
hub / github.com/ipython/ipython / rerun

Method rerun

IPython/core/magics/history.py:280–318  ·  view source on GitHub ↗

Re-run previous input By default, you can specify ranges of input history to be repeated (as with %history). With no arguments, it will repeat the last line. Options: -l : Repeat the last n lines of input, not including the current command.

(self, parameter_s='')

Source from the content-addressed store, hash-verified

278
279 @line_magic
280 def rerun(self, parameter_s=''):
281 """Re-run previous input
282
283 By default, you can specify ranges of input history to be repeated
284 (as with %history). With no arguments, it will repeat the last line.
285
286 Options:
287
288 -l <n> : Repeat the last n lines of input, not including the
289 current command.
290
291 -g foo : Repeat the most recent line which contains foo
292 """
293 opts, args = self.parse_options(parameter_s, 'l:g:', mode='string')
294 if "l" in opts: # Last n lines
295 n = int(opts['l'])
296 hist = self.shell.history_manager.get_tail(n)
297 elif "g" in opts: # Search
298 p = "*"+opts['g']+"*"
299 hist = list(self.shell.history_manager.search(p))
300 for l in reversed(hist):
301 if "rerun" not in l[2]:
302 hist = [l] # The last match which isn't a %rerun
303 break
304 else:
305 hist = [] # No matches except %rerun
306 elif args: # Specify history ranges
307 hist = self.shell.history_manager.get_range_by_str(args)
308 else: # Last line
309 hist = self.shell.history_manager.get_tail(1)
310 hist = [x[2] for x in hist]
311 if not hist:
312 print("No lines in history match specification")
313 return
314 histlines = "\n".join(hist)
315 print("=== Executing: ===")
316 print(histlines)
317 print("=== Output: ===")
318 self.shell.run_cell("\n".join(hist), store_history=False)

Callers

nothing calls this directly

Calls 5

parse_optionsMethod · 0.80
get_tailMethod · 0.45
searchMethod · 0.45
get_range_by_strMethod · 0.45
run_cellMethod · 0.45

Tested by

no test coverage detected