Package glue :: Package ligolw :: Module tokenizer :: Class RowDumper
[hide private]
[frames] | no frames]

Class RowDumper

object --+
         |
        RowDumper

An iterator for converting row objects into string tokens.

Example:

>>> class Row(object):
...     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.

Instance Methods [hide private]
 
__init__(...)
x.__init__(...) initializes x; see help(type(x)) for signature
 
__iter__(x)
iter(x)
a new object with type S, a subtype of T
__new__(T, S, ...)
 
dump(...)
Set the Python iterable from which row objects will be retrieved for dumping.
the next value, or raise StopIteration
next(x)

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]
  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.

Inherited from object: __class__

Method Details [hide private]

__init__(...)
(Constructor)

 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__

__new__(T, S, ...)

 
Returns: a new object with type S, a subtype of T
Overrides: object.__new__