Mercurial > hg > numerics
changeset 44:7927d7127f9a
add sensible csv writer
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Fri, 09 Jan 2015 14:17:33 -0800 |
parents | bcf9ec537bda |
children | ef915968d104 |
files | numerics/csvwriter.py |
diffstat | 1 files changed, 19 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/numerics/csvwriter.py Fri Jan 09 14:17:33 2015 -0800 @@ -0,0 +1,19 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import csv +string = (str, unicode) +__all__ = ['CSVWriter'] + +class CSVWriter(object): + """a more sensible front-end to writing CSV files""" + + def __init__(self, f, mode='a'): + if isinstance(f, string): + f = open(f, mode) + self.f = f + self.writer = csv.writer(f) + + def __call__(self, *data): + self.writer.writerow(data) + self.f.flush()