RowDumper¶
- class igwn_ligolw.tokenizer.RowDumper¶
Bases:
objectAn iterator for converting row objects into string tokens.
Example:
>>> class Row: ... pass ... >>> rows = [Row(), Row(), Row()] >>> rows[0].snr = 10.1 >>> rows[1].snr = 15.2 >>> rows[2].snr = 20.3 >>> rows[0].status = "bad" >>> rows[1].status = "bad" >>> rows[2].status = "good" >>> rowdumper = RowDumper(("snr", "status"), ("%.16g".__mod__, "\"%s\"".__mod__)) >>> for line in rowdumper.dump(rows): ... print(line) ... 10.1,"bad" 15.2,"bad" 20.3,"good"
An instance of RowDumper is initialized with two arguments and an optional third argument. The first argument is a sequence of attribute names. The second argument is a sequence of Python format strings. The third, optional, argument is the unicode string to use as the delimiter between tokens (the default is u”,”). The row dumper is started by calling the .dump() method which takes a Python iterable as its single argument. After the .dump() method has been called, when a RowDumper instance is iterated over it retrieves objects, one-by-one, from the iterable passed to the .dump() method and yields a sequence of unicode strings containing the delimited string representations of the values of the attributes of those objects. The attribute values are printed in the order specified when the RowDumper was created, and using the formats specified. An attribute whose value is None is printed as an empty string regardless of the requested format.
Attributes Summary
In-order tuple of attribute names as strings.
The delimiter as a unicode string.
In-order tuple of row element format functions.
The iterator being used to provide rows for conversion.
Count of rows converted.
In-order tuple of unicode tokens from most recently converted row.
Methods Summary
Set the Python iterable from which row objects will be retrieved for dumping.
Attributes Documentation
- attributes¶
In-order tuple of attribute names as strings.
- delimiter¶
The delimiter as a unicode string.
- formats¶
In-order tuple of row element format functions.
- iter¶
The iterator being used to provide rows for conversion.
- rows_converted¶
Count of rows converted.
- tokens¶
In-order tuple of unicode tokens from most recently converted row.
Methods Documentation
- dump()¶
Set the Python iterable from which row objects will be retrieved for dumping.