简单structuredText表的表读取器
tableread的Python项目详细描述
tableread是一个脚本,用于从文件中读取restractredtext(rest)simple tables,并将其转换为python对象。
快速启动
假设您有一个这样的简单表,它位于./example.rst:
++++++++++++ Damage Doers ++++++++++++ ====== === ============== Name Age Favorite Color ====== === ============== Mookie 26 Red Andrew 24 Red JD 31 Red Xander 26 Red ====== === ==============
下面是一些有用的东西,您可以使用该表:
>>> from tableread import SimpleRSTReader >>> >>> reader = SimpleRSTReader("./example.rst") >>> reader.tables ['Damage Doers'] >>> >>> table = reader["Damage Doers"] >>> table.fields ['name', 'age', 'favorite_color'] >>> >>> for row in table: ... print(row.favorite_color) ... Red Red Red Red >>> >>> for row in table.matches_all(age="26"): ... print(row.name) ... Mookie Xander >>> >>> for row in table.exclude_by(age="26"): ... print(row.name) ... Andrew JD
用法
class tableread.SimpleRSTReader(file_path)
Parse a reStructredText file, ^{tt3}$, and convert any simple tables into ^{tt4}$ objects. Individual tables can be accessed using the table name as the key (^{tt5}$)
- 数据
- 在rest文件中找到的表的ordereddict。关键是 文件中表名前面的节头,或不在头下的表的Default。 对于一个节中的多个表(或多个Default表), 随后的表将在键后面附加一个递增的数字:Default,Default_2,等等。 值是一个SimpleRSTTable对象。
- 表
- 表名列表;用于list(data.keys()) 的别名
- 第一个
- 获取文件中找到的第一个表的助手;的别名 list(self.data.values())[0]
class tableread.SimpleRSTTable(header, rows, column_spans)
A representation of an individual table. In addition to the methods below, you may iterate over the table itself as a shortcut (^{tt14}$), which will yield from ^{tt15}$. ^{tt16}$ will also return the number of entries in ^{tt15}$.
- 数据
- 一个名为fields的名为duples的列表。
- 字段
- 表字段的元组,用于datanamedtuple。 字段名通过下框从表列改编而来, 并用下划线替换空格和句点。
- 来自数据(数据)
- 用于创建对象的辅助函数。需要一个已准备好的名称对列表。
- 匹配所有(**kwargs)
给定一组键/值筛选器,返回一个新的TableRead对象 过滤后的数据,可以迭代。 值可以是简单值(str,int)或返回布尔值的函数。 有关示例,请参见Quickstart。
注意:当筛选键和值时不区分大小写。
- exclude_by(**kwargs)
给定一组键/值筛选器,返回一个不带 匹配的数据,可以迭代。 值可以是简单值(str,int)或返回布尔值的函数。 有关示例,请参见Quickstart。
注意:当筛选键和值时不区分大小写。
- get_fields(*字段)
- 给定一个字段列表,只返回与这些字段相关联的值的列表。 单个字段返回值列表,多个字段返回值元组列表。