mirror of
https://github.com/kennethreitz/tablib.git
synced 2026-06-05 23:10:17 +00:00
.append
This commit is contained in:
+17
-8
@@ -25,8 +25,10 @@ class Dataset(object):
|
||||
"""Amazing Tabular Dataset object. """
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self._data = None
|
||||
self._filename = None
|
||||
|
||||
self._data = [].append(args)
|
||||
self._data = list(args)
|
||||
|
||||
try:
|
||||
self.headers = kwargs['headers']
|
||||
@@ -37,7 +39,6 @@ class Dataset(object):
|
||||
def __len__(self):
|
||||
return self.height
|
||||
|
||||
|
||||
def __getitem__(self, key):
|
||||
|
||||
if is_string(key):
|
||||
@@ -94,9 +95,9 @@ class Dataset(object):
|
||||
"""Returns the width of the Dataset."""
|
||||
|
||||
try:
|
||||
len(self._data[0])
|
||||
except Exception, why:
|
||||
raise why
|
||||
return len(self._data[0])
|
||||
except KeyError, why:
|
||||
return 0
|
||||
|
||||
|
||||
@property
|
||||
@@ -121,18 +122,26 @@ class Dataset(object):
|
||||
|
||||
|
||||
def append(self, row, index=None):
|
||||
pass
|
||||
# todo: impliment index
|
||||
self.validate(row)
|
||||
self._data.append(row)
|
||||
|
||||
def del_row(self):
|
||||
def sort_by(self, key):
|
||||
"""Returns datastet sorted by given key"""
|
||||
# todo: accpept string if headers, or index nubmer
|
||||
pass
|
||||
|
||||
def save(self):
|
||||
pass
|
||||
|
||||
# note export format
|
||||
# open file, save the bitch
|
||||
|
||||
class InvalidDimensions(Exception):
|
||||
"Invalid size"
|
||||
|
||||
|
||||
def source():
|
||||
def source(io_string=None, filename=None):
|
||||
"""docstring for import"""
|
||||
#open by filename
|
||||
pass
|
||||
@@ -0,0 +1,17 @@
|
||||
import tablib
|
||||
|
||||
headers = ('first_name', 'last_name', 'gpa')
|
||||
|
||||
data = [
|
||||
('John', 'Adams', 4.0),
|
||||
('George', 'Washington', 2.6),
|
||||
('Henry', 'Ford', 2.3)
|
||||
]
|
||||
|
||||
data = tablib.Dataset(*data, headers=headers)
|
||||
|
||||
print data[1]
|
||||
data.append(['kenneth' ,'reitz', 4.3])
|
||||
|
||||
|
||||
print data._data
|
||||
Reference in New Issue
Block a user