diff options
| author | Kenneth Reitz <me@kennethreitz.com> | 2010-11-04 04:13:02 -0400 |
|---|---|---|
| committer | Kenneth Reitz <me@kennethreitz.com> | 2010-11-04 04:13:02 -0400 |
| commit | fcada243a234532cc8e9282eb96f4b6049e915f3 (patch) | |
| tree | c3f12a2aec26131b476aeabc6b4702fcf952390b /tablib/core.py | |
| parent | fca8ad6182ea8381bfce5984ff47629090fafc02 (diff) | |
| download | tablib-fcada243a234532cc8e9282eb96f4b6049e915f3.tar.gz | |
Added new Row class and Dataset.filter().
Diffstat (limited to 'tablib/core.py')
| -rw-r--r-- | tablib/core.py | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/tablib/core.py b/tablib/core.py index 3346cb9..ede3b13 100644 --- a/tablib/core.py +++ b/tablib/core.py @@ -150,7 +150,12 @@ class Dataset(object): else: raise KeyError else: - return tuple(self._data[key]) + _results = self._data[key] + if isinstance(_results, Row): + return _results.tuple + else: + return [result.tuple for result in _results] + def __setitem__(self, key, value): @@ -453,11 +458,10 @@ class Dataset(object): if self.height and self.width: for i, row in enumerate(self._data): - _row = list(row) - _row.append(col[i]) - self._data[i] = tuple(_row) + row.append(col[i]) + self._data[i] = row else: - self._data = [tuple([row]) for row in col] + self._data = [Row([row]) for row in col] def insert_separator(self, index, text='-'): @@ -479,7 +483,7 @@ class Dataset(object): self.insert_separator(index, text) - def insert(self, index, row=None, col=None): + def insert(self, index, row=None, col=None, tags=list()): """Inserts a row or column to the :class:`Dataset` at the given index. Rows and columns inserted must be the correct size (height or width). @@ -498,7 +502,7 @@ class Dataset(object): """ if row: self._validate(row) - self._data.insert(i, Row(row)) + self._data.insert(i, Row(row, tags=tags)) elif col: col = self._clean_col(col) @@ -512,11 +516,11 @@ class Dataset(object): if self.height and self.width: for i, row in enumerate(self._data): - _row = list(row) - _row.insert(index, col[i]) - self._data[i] = tuple(_row) + + row.insert(index, col[i]) + self._data[i] = row else: - self._data = [tuple([row]) for row in col] + self._data = [Row([row]) for row in col] def filter(self, tag): """Returns a new instance of the :class:`Dataset` containing only rows |
