diff options
| author | Kenneth Reitz <me@kennethreitz.com> | 2010-10-10 03:03:50 -0400 |
|---|---|---|
| committer | Kenneth Reitz <me@kennethreitz.com> | 2010-10-10 03:03:50 -0400 |
| commit | 08b51113d314aa9abe063e7ec8e5c1da41c6fb9a (patch) | |
| tree | cd9d1378be6c46c9d086980d5a8db03db3519da0 | |
| parent | 3e391fc8e39bc8a646a329d84b2c428f0997faab (diff) | |
| download | tablib-08b51113d314aa9abe063e7ec8e5c1da41c6fb9a.tar.gz | |
Added seamless deletion of columns.
| -rw-r--r-- | tablib/core.py | 22 | ||||
| -rw-r--r-- | tablib/formats/__init__.py | 2 |
2 files changed, 18 insertions, 6 deletions
diff --git a/tablib/core.py b/tablib/core.py index 1ab2e00..3bfc312 100644 --- a/tablib/core.py +++ b/tablib/core.py @@ -9,7 +9,7 @@ :license: MIT, see LICENSE for more details. """ -from tablib.formats import FORMATS as formats +from tablib import formats __title__ = 'tablib' @@ -95,7 +95,19 @@ class Dataset(object): def __delitem__(self, key): - del self._data[key] + if isinstance(key, basestring): + if key in self.headers: + pos = self.headers.index(key) + del self.headers[pos] + + for i, row in enumerate(self._data): + _row = list(row) + del _row[pos] + self._data[i] = tuple(_row) + else: + raise KeyError + else: + del self._data[key] def __repr__(self): @@ -108,7 +120,7 @@ class Dataset(object): @classmethod def _register_formats(cls): """Adds format properties.""" - for fmt in formats: + for fmt in formats.available: try: try: setattr(cls, fmt.title, property(fmt.export_set, fmt.import_set)) @@ -453,7 +465,7 @@ class Databook(object): @classmethod def _register_formats(cls): """Adds format properties.""" - for fmt in formats: + for fmt in formats.available: try: try: setattr(cls, fmt.title, property(fmt.export_book, fmt.import_book)) @@ -491,7 +503,7 @@ class Databook(object): def detect(stream): """Return (format, stream) of given stream.""" - for fmt in formats: + for fmt in formats.available: try: if fmt.detect(stream): return (fmt, stream) diff --git a/tablib/formats/__init__.py b/tablib/formats/__init__.py index 69eada7..0ce9b71 100644 --- a/tablib/formats/__init__.py +++ b/tablib/formats/__init__.py @@ -8,4 +8,4 @@ import _json as json import _xls as xls import _yaml as yaml -FORMATS = (json, xls, yaml, csv) +available = (json, xls, yaml, csv) |
