The serial-python Python library provides extensible tools for reading and
writing record-oriented data in various formats. The core library provided here
is contained in the serial.core
package. Library extensions will be
contained in their own packages under the serial
namespace.
- Read/write delimited and fixed-width data
- Named, typed, and formatted data fields
- Filtering
- Aggregation
- Sorting
""" Read a comma-delimited file.
"""
from serial.core import DelimitedReader
from serial.core import IntField
from serial.core import StringField
def name_filter(record):
""" Convert name to upper case. """
record["name"] = record["name"].upper()
return record
fields = (
StringField("name", 0),
IntField("age", 1)
)
with DelimitedReader.open("ages.csv", fields, ",") as reader:
reader.filter(name_filter)
for record in reader:
print("{name} is {age} years old".format(**record))
Install the library from GitHub:
$ python -m pip install git+git://github.com/mdklatt/serial-python.git