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

Method edit

IPython/lib/demo.py:386–414  ·  view source on GitHub ↗

Edit a block. If no number is given, use the last block executed. This edits the in-memory copy of the demo, it does NOT modify the original source file. If you want to do that, simply open the file in an editor and use reload() when you make changes to the file.

(self,index=None)

Source from the content-addressed store, hash-verified

384 self()
385
386 def edit(self,index=None):
387 """Edit a block.
388
389 If no number is given, use the last block executed.
390
391 This edits the in-memory copy of the demo, it does NOT modify the
392 original source file. If you want to do that, simply open the file in
393 an editor and use reload() when you make changes to the file. This
394 method is meant to let you change a block during a demonstration for
395 explanatory purposes, without damaging your original script."""
396
397 index = self._get_index(index)
398 if index is None:
399 return
400 # decrease the index by one (unless we're at the very beginning), so
401 # that the default demo.edit() call opens up the sblock we've last run
402 if index>0:
403 index -= 1
404
405 filename = self.shell.mktempfile(self.src_blocks[index])
406 self.shell.hooks.editor(filename,1)
407 with open(filename, 'r') as f:
408 new_block = f.read()
409 # update the source and colored block
410 self.src_blocks[index] = new_block
411 self.src_blocks_colored[index] = self.highlight(new_block)
412 self.block_index = index
413 # call to run with the newly edited index
414 self()
415
416 def show(self,index=None):
417 """Show a single block on screen"""

Callers

nothing calls this directly

Calls 4

_get_indexMethod · 0.95
highlightMethod · 0.95
mktempfileMethod · 0.80
readMethod · 0.80

Tested by

no test coverage detected