ANN: csvutils 0.1

G

George Sakkis

csvutils is a single Python module for easily transforming csv (or csv-
like) generated rows. The release is available at http://pypi.python.org/pypi/csvutils/0.1.

Regards,
George

What is csvutils?
------------------------
The standard csv module is very useful for parsing tabular data in CSV
format. Typically though, one or more transformations need to be
applied to the generated rows before being ready to be used; for
instance "convert the 3rd column to int, the 5th to float and ignore
all the rest". csvutils provides an easy way to specify such
transformations upfront instead of coding them every time by hand.
Here are a few examples (more included as doctests):
>>> import csv
>>> from csvutils import SequenceTransformer
>>> rows = list(csv.reader(["1,3.34,4-3.2j,John",
... "4,4,4,4",
... "0,-1.1,3.4,None"])) ... print row
[1, 3.3399999999999999]
[4, 4.0]
[0, -1.1000000000000001] ... print row
['1', 3.3399999999999999, '4-3.2j', 'John']
['4', 4.0, '4', '4']
['0', -1.1000000000000001, '3.4', 'None']
>>> # exclude the 4th column and eval() the rest (XXX: Use eval for trusted data only)
>>> 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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top