summaryrefslogtreecommitdiff
path: root/tablib
diff options
context:
space:
mode:
authorKenneth Reitz <me@kennethreitz.com>2010-08-30 05:31:45 -0400
committerKenneth Reitz <me@kennethreitz.com>2010-08-30 05:31:45 -0400
commit37ffbc71c009b027d3ffa522a0a3f546d6ac7a7c (patch)
tree81e8575d129423d597c134fb66be0f1535fe1fde /tablib
parent6f7c64eb03b80f4bff2d44e13b6e0cd19749967d (diff)
downloadtablib-37ffbc71c009b027d3ffa522a0a3f546d6ac7a7c.tar.gz
index and append methods
Diffstat (limited to 'tablib')
-rw-r--r--tablib/core.py14
-rw-r--r--tablib/tests/tests.py8
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