diff --git a/tablib/core.py b/tablib/core.py index 0a8fce7..8f08714 100644 --- a/tablib/core.py +++ b/tablib/core.py @@ -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 \ No newline at end of file diff --git a/tablib/tests/tests.py b/tablib/tests/tests.py new file mode 100644 index 0000000..f457dfb --- /dev/null +++ b/tablib/tests/tests.py @@ -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 \ No newline at end of file