RowBuilder

class igwn_ligolw.tokenizer.RowBuilder

Bases: object

This class provides the logic required to transform a sequence of of tokens parsed out of the delimited text of a Stream element into a sequence of row objects for insertion into a Table element. An instance of this class is initialized with a Python class to be instantiated to form row objects, and an iterable providing the names of the row class’ attributes to which tokens will be assigned in order.

Example:

>>> from igwn_ligolw import tokenizer
>>> class Row:
...     pass
...
>>> t = tokenizer.Tokenizer(u",")
>>> t.set_types([int, float])
>>> rows = tokenizer.RowBuilder(Row, ["time", "snr"])
>>> l = list(rows.append(t.append(u"10,6.8,15,29.1,")))
>>> l[0].snr
6.8
>>> l[1].time
15

Attributes Summary

attributes

in-order tuple of attribute names

i

current attribute index

row

current row object

rowtype

row class

Methods Summary

append

Append a sequence of tokens to the row builder, returning an iterator for generating a sequence of new row instances.

Attributes Documentation

attributes

in-order tuple of attribute names

i

current attribute index

row

current row object

rowtype

row class

Methods Documentation

append()

Append a sequence of tokens to the row builder, returning an iterator for generating a sequence of new row instances. The tokens argument should be an iterable, producing a sequence of token objects. If fewer tokens are yielded from the iterable than are required to construct a complete row, then the row is stored in its partially-populated state and its construction will continue upon the next invocation. Note that it is possible that a call to this method will yield no new rows at all.

Example:

>>> from igwn_ligolw import tokenizer
>>> class Row:
...     pass
...
>>> rows = tokenizer.RowBuilder(Row, ["time", "snr"])
>>> for row in rows.append([10, 6.8, 15, 29.1]):
...     print(row.snr)
...
6.8
29.1