old_contents: #!/usr/bin/env python
  """Convert IPython notebooks to other formats, such as ReST, and HTML.
  
  Example:
    ./nbconvert.py --format rst file.ipynb
  
  Produces 'file.rst', along with auto-generated figure files
  called nb_figure_NN.png.
  """
  #-----------------------------------------------------------------------------
  # Imports
  #-----------------------------------------------------------------------------
  from __future__ import print_function
  from collections import OrderedDict
  
  # From IPython
  from IPython.external import argparse
  
  # local
  from converters.html import ConverterHTML
  from converters.markdown import ConverterMarkdown
  from converters.bloggerhtml import ConverterBloggerHTML
  from converters.rst import ConverterRST
  from converters.latex import ConverterLaTeX
  from converters.notebook import ConverterNotebook
  from converters.python import ConverterPy
  
  
  # When adding a new format, make sure to add it to the `converters`
  # dictionary below. This is used to create the list of known formats,
  # which gets printed in case an unknown format is encounteres, as well
  # as in the help
  
  converters = OrderedDict([
          ('rst', ConverterRST),
          ('markdown', ConverterMarkdown),
          ('html', ConverterHTML),
          ('blogger-html', ConverterBloggerHTML),
          ('latex', ConverterLaTeX),
          ('py', ConverterPy),
          ])
  
  default_format = 'py'
  
  # Extract the list of known formats and mark the first format as the default.
  known_formats = ', '.join([key + " (default)" if key == default_format else key
                             for key in converters.keys()])
  
  
  def main(infile, format='rst'):
      """Convert a notebook to html in one step"""
  
      try:
          ConverterClass = converters[format]
      except KeyError:
          raise SystemExit("Unknown format '%s', " % format +
                  "known formats are: " + known_formats)
  
      converter = ConverterClass(infile)
      converter.render()
  
  #-----------------------------------------------------------------------------
  # Script main
  #-----------------------------------------------------------------------------
  
  if __name__ == '__main__':
      parser = argparse.ArgumentParser(description=__doc__,
              formatter_class=argparse.RawTextHelpFormatter)
      # TODO: consider passing file like object around, rather than filenames
      # would allow us to process stdin, or even http streams
      #parser.add_argument('infile', nargs='?', type=argparse.FileType('r'), default=sys.stdin)
  
      #Require a filename as a positional argument
      parser.add_argument('infile', nargs=1)
      parser.add_argument('-f', '--format', default='rst',
                          help='Output format. Supported formats: \n' +
                          known_formats)
      args = parser.parse_args()
      main(infile=args.infile[0], format=args.format)
  
new_contents: #!/usr/bin/env python
  """Convert IPython notebooks to other formats, such as ReST, and HTML.
  
  Example:
    ./nbconvert.py --format rst file.ipynb
  
  Produces 'file.rst', along with auto-generated figure files
  called nb_figure_NN.png.
  """
  #-----------------------------------------------------------------------------
  # Imports
  #-----------------------------------------------------------------------------
  from __future__ import print_function
  
  # From IPython
  from IPython.external import argparse
  
  # local
  from converters.html import ConverterHTML
  from converters.markdown import ConverterMarkdown
  from converters.bloggerhtml import ConverterBloggerHTML
  from converters.rst import ConverterRST
  from converters.latex import ConverterLaTeX
  from converters.notebook import ConverterNotebook
  from converters.python import ConverterPy
  
  
  # When adding a new format, make sure to add it to the `converters`
  # dictionary below. This is used to create the list of known formats,
  # which gets printed in case an unknown format is encounteres, as well
  # as in the help
  
  converters = {
      'rst': ConverterRST,
      'markdown': ConverterMarkdown,
      'html': ConverterHTML,
      'blogger-html': ConverterBloggerHTML,
      'latex': ConverterLaTeX,
      'py': ConverterPy,
      }
  
  default_format = 'rst'
  
  # Extract the list of known formats and mark the first format as the default.
  known_formats = ', '.join([key + " (default)" if key == default_format else key
                             for key in converters.keys()])
  
  
  def main(infile, format='rst'):
      """Convert a notebook to html in one step"""
  
      try:
          ConverterClass = converters[format]
      except KeyError:
          raise SystemExit("Unknown format '%s', " % format +
                  "known formats are: " + known_formats)
  
      converter = ConverterClass(infile)
      converter.render()
  
  #-----------------------------------------------------------------------------
  # Script main
  #-----------------------------------------------------------------------------
  
  if __name__ == '__main__':
      parser = argparse.ArgumentParser(description=__doc__,
              formatter_class=argparse.RawTextHelpFormatter)
      # TODO: consider passing file like object around, rather than filenames
      # would allow us to process stdin, or even http streams
      #parser.add_argument('infile', nargs='?', type=argparse.FileType('r'), default=sys.stdin)
  
      #Require a filename as a positional argument
      parser.add_argument('infile', nargs=1)
      parser.add_argument('-f', '--format', default='rst',
                          help='Output format. Supported formats: \n' +
                          known_formats)
      args = parser.parse_args()
      main(infile=args.infile[0], format=args.format)
  
subject: Use a regular dictionary instead of OrderedDict.