From 37ffbc71c009b027d3ffa522a0a3f546d6ac7a7c Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Mon, 30 Aug 2010 05:31:45 -0400 Subject: [PATCH] index and append methods --- tablib/core.py | 14 ++++++++------ tablib/tests/tests.py | 8 ++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/tablib/core.py b/tablib/core.py index 2e86cb4..5427221 100644 --- a/tablib/core.py +++ b/tablib/core.py @@ -171,12 +171,16 @@ class Dataset(object): return stream.getvalue() - def append(self, row, index=None): - # todo: impliment index + def append(self, row): + """Adds a row to the end of Dataset""" self._validate(row) self._data.append(tuple(row)) - + def index(self, i, row): + """Inserts a row at given position in Dataset""" + self._validate(row) + self._data.insert(i, tuple(row)) + def sort_by(self, key): """Sorts datastet by given key""" # todo: accpept string if headers, or index nubmer @@ -186,9 +190,7 @@ class Dataset(object): def save(self, filename=None, format=None): """Saves dataset""" if not format: - # set format from filename -# format = filename - pass + format = filename.split('.')[-1].lower() # set format from filename if format not in FILE_EXTENSIONS: raise UnsupportedFormat diff --git a/tablib/tests/tests.py b/tablib/tests/tests.py index 89d9a9c..55fa083 100644 --- a/tablib/tests/tests.py +++ b/tablib/tests/tests.py @@ -20,7 +20,7 @@ data.append(['kenneth' ,'reitz', 4.3]) #print data.json data.headers = None -#print data.csv -print len(data.xls) -#print data.yaml -#print data.json \ No newline at end of file +print data.csv +#print len(data.xls) +print data.yaml +print data.json \ No newline at end of file