class_docstr: A Python notebook writer.
docstr: Convert a notebook object to a string.
docstr_tok: ["Convert","a","notebook","object","to","a","string","."]
code: def writes(self, nb, **kwargs):
      """Convert a notebook object to a string."""
      lines = ["# -*- coding: utf-8 -*-"]
      lines.extend(["# <nbformat>2</nbformat>", ""])
      for ws in nb.worksheets:
          for cell in ws.cells:
              if cell.cell_type == "code":
                  input_ = cell.get("input")
                  if input_ is not None:
                      lines.extend(["# <codecell>", ""])
                      lines.extend(input_.splitlines())
                      lines.append("")
              elif cell.cell_type == "html":
                  input_ = cell.get("source")
                  if input_ is not None:
                      lines.extend(["# <htmlcell>", ""])
                      lines.extend(
                          ["# " + line for line in input_.splitlines()]
                      )
                      lines.append("")
              elif cell.cell_type == "markdown":
                  input_ = cell.get("source")
                  if input_ is not None:
                      lines.extend(["# <markdowncell>", ""])
                      lines.extend(
                          ["# " + line for line in input_.splitlines()]
                      )
                      lines.append("")
      lines.append("")
      return str("\n".join(lines))
  
file_path: nbformat/nbformat/v2/nbpy.py
imports: from __future__ import annotations
  import re
  from .nbbase import new_code_cell, new_notebook, new_text_cell, new_worksheet
  from .rwbase import NotebookReader, NotebookWriter
label_desc: Use image node_id 1 for calling the PyWriter obj's underlying member method code with example usage: obj.writes(nb) and returns: str