docstr: 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.  This
  method is meant to let you change a block during a demonstration for
  explanatory purposes, without damaging your original script.
docstr_tok: ["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",".","This","method","is","meant","to","let","you","change","a","block","during","a","demonstration","for","explanatory","purposes",",","without","damaging","your","original","script","."]
code: def edit(self, index=None):
      """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.  This
      method is meant to let you change a block during a demonstration for
      explanatory purposes, without damaging your original script."""
  
      index = self._get_index(index)
      if index is None:
          return
      # decrease the index by one (unless we're at the very beginning), so
      # that the default demo.edit() call opens up the sblock we've last run
      if index > 0:
          index -= 1
  
      filename = self.shell.mktempfile(self.src_blocks[index])
      self.shell.hooks.editor(filename, 1)
      with open(Path(filename), "r", encoding="utf-8") as f:
          new_block = f.read()
      # update the source and colored block
      self.src_blocks[index] = new_block
      self.src_blocks_colored[index] = self.highlight(new_block)
      self.block_index = index
      # call to run with the newly edited index
      self()
  
imports: import os
  import re
  import shlex
  import sys
  import pygments
  from pathlib import Path
  from IPython.utils.text import marquee
  from IPython.utils import openpy
  from IPython.utils import py3compat
label_desc: Use image node_id 11 for calling the Demo obj's underlying member method code with example usage: obj.edit(index) without return types