RST#

class astropy.io.ascii.RST(header_rows=None)[源代码]#

基类:FixedWidth

reStructuredText简单格式表。

参见:https://docutils.sourceforge.io/docs/ref/rst/restructedText.htmlsimple-表格

例子::

>>> 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
===== ========

与其他固定宽度格式一样,在编写表格时,您可以提供 header_rows 若要指定要作为标题输出的表行列表,请执行以下操作。例如::

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

目前不支持读取使用连续行的表,也不支持通过在页眉中使用另一行破折号来定义列跨距的表。

方法总结

read \(表)

阅读 table 并以由确定的格式返回结果 outputter 属性。

write \(行)

table 作为字符串列表。

方法文件

read(table)[源代码]#

阅读 table 并以由确定的格式返回结果 outputter 属性。

这个 table 参数是实例可以处理的任何字符串或对象 inputter . 对于基本输入程序类 table 可以是:

  • 文件名

  • 文件状对象

  • 所有标题和数据行的字符串(换行符分开)(必须至少有2行)

  • 字符串列表

参数:
table : strfile-like objectlistPYTHON:字符串,PYTHON:类似文件的对象,PYTHON:列表

输入表。

返回:
桌子Table

输出表

write(lines)[源代码]#

table 作为字符串列表。

参数:
桌子Table

输入表格数据。

返回:
lines : listPython :列表

ASCII表对应的字符串列表