Skip to main content
`Ctrl`+`K`

# RST

class astropy.io.ascii.RST(header_rows=None)

  Bases: `FixedWidth`

  reStructuredText simple format table.

  See: https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#simple-tables

  Example:

      >>> from astropy.table import QTable
      >>> import astropy.units as u
      >>> import sys
      >>> tbl = QTable({"wave": [350, 950] * u.nm, "response": [0.7, 1.2] * u.count})
      >>> tbl.write(sys.stdout,  format="ascii.rst")
      ===== ========
       wave response
      ===== ========
      350.0      0.7
      950.0      1.2
      ===== ========

  Like other fixed-width formats, when writing a table you can provide `header_rows` to specify a list of table rows to output as the header. For example:

      >>> tbl.write(sys.stdout,  format="ascii.rst", header_rows=['name', 'unit'])
      ===== ========
       wave response
         nm       ct
      ===== ========
      350.0      0.7
      950.0      1.2
      ===== ========

  Currently there is no support for reading tables which utilize continuation lines, or for ones which define column spans through the use of an additional line of dashes in the header.

  Methods Summary

  `read`(table) | Read the `table` and return the results in a format determined by the `outputter` attribute.
  `write`(lines) | Write the table data in RST format including header and footer separator lines.

  Methods Documentation

  read(table)

    Read the `table` and return the results in a format determined by the `outputter` attribute.

    The `table` parameter is any string or object that can be processed by the instance `inputter`. For the base Inputter class `table` can be one of:

    - File name

    - File-like object

    - String (newline separated) with all header and data lines (must have at least 2 lines)

    - List of strings

    Parameters:
      table `python:str`, python:file-like object, `python:list`

        Input table.

    Returns:
      table `Table`

        Output table

  write(lines)

    Write the table data in RST format including header and footer separator lines.

    Parameters:
      lines `python:list` of `python:str`

        The formatted table lines to be written.

    Returns:
      `python:list`[`python:str`]

        The complete RST table with header separator, table content, and footer separator line.