# HG changeset patch # User Jeff Hammel # Date 1420841853 28800 # Node ID 7927d7127f9abcf6edcc8b7149102f3cb5de68ee # Parent bcf9ec537bda3c4ea59616f9a80e774a45e29881 add sensible csv writer diff -r bcf9ec537bda -r 7927d7127f9a numerics/csvwriter.py --- /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()