Class SequenceTransformer
source code
object --+
|
RowTransformer --+
|
SequenceTransformer
A RowTransformer that expects and returns rows as
sequences.
Examples:
>>> import csv
>>> rows = list(csv.reader(["1,3.34,4-3.2j,John",
... "4,4,4,4",
... "0,-1.1,3.4,None"]))
>>>
>>> list(SequenceTransformer()(rows)) == rows
True
>>>
>>> for row in SequenceTransformer(int,float)(rows):
... print row
[1, 3.3399999999999999]
[4, 4.0]
[0, -1.1000000000000001]
>>>
>>> for row in SequenceTransformer(int, float, default=None)(rows):
... print row
[1, 3.3399999999999999, '4-3.2j', 'John']
[4, 4.0, '4', '4']
[0, -1.1000000000000001, '3.4', 'None']
>>>
>>> for row in SequenceTransformer(int, float, default=None,
... include=reversed(xrange(4)))(rows):
... print row
['John', '4-3.2j', 3.3399999999999999, 1]
['4', '4', 4.0, 4]
['None', '3.4', -1.1000000000000001, 0]
>>>
>>> for row in SequenceTransformer((1,float), default=None)(rows):
... print row
['1', 3.3399999999999999, '4-3.2j', 'John']
['4', 4.0, '4', '4']
['0', -1.1000000000000001, '3.4', 'None']
>>>
>>> for row in SequenceTransformer((3,str),(1,float))(rows):
... print row
['John', 3.3399999999999999]
['4', 4.0]
['None', -1.1000000000000001]
>>>
>>> for row in SequenceTransformer(default=eval, exclude=[3])(rows):
... print row
[1, 3.3399999999999999, (4-3.2000000000000002j)]
[4, 4, 4]
[0, -1.1000000000000001, 3.3999999999999999]
|
__init__(self,
*adaptors,
**kwds)
Specifies what transformations to apply to each row. |
source code
|
|
|
|
Inherited from object :
__delattr__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__setattr__ ,
__str__
|
Inherited from object :
__class__
|
__init__(self,
*adaptors,
**kwds)
(Constructor)
| source code
|
Specifies what transformations to apply to each row.
- Parameters:
adaptors - The adaptors for selected columns. The i-th adaptor can
be:
-
None:
row[i] will be left as is.
-
A callable
f(x) : row[i] will be
transformed by f to f(row[i]) .
-
A pair
(j,A) : row[j] will be
transformed by adaptor A, where A can be None or
a callable f(x) as above. i is
ignored in this case.
include - It can be:
-
An iterable of indices: Only the items at the respective
columns are included (except for those that are also in
exclude ).
-
A positive integer N: shortcut for
xrange(N) .
default , exclude - See RowTransformer.__init__
- Overrides:
RowTransformer.__init__
|
Transform the given rows by this transformer.
- Parameters:
rows - An iterable of sequences.
- Returns:
- An iterator over the transformed rows as lists.
- Overrides:
RowTransformer.__call__
|