diff options
| author | Kenneth Reitz <me@kennethreitz.com> | 2010-08-30 02:32:57 -0400 |
|---|---|---|
| committer | Kenneth Reitz <me@kennethreitz.com> | 2010-08-30 02:32:57 -0400 |
| commit | 8d44ad8a12bca0abf875606049f8793ada71a698 (patch) | |
| tree | 85b50ddcbdb66b3f14d2901a09203a9db580941b /tablib | |
| parent | 1850a934aa4f11c04df32676090546f88aa83483 (diff) | |
| download | tablib-8d44ad8a12bca0abf875606049f8793ada71a698.tar.gz | |
YAML export support complete.
Diffstat (limited to 'tablib')
| -rw-r--r-- | tablib/core.py | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/tablib/core.py b/tablib/core.py index 53f4616..ddcd9a6 100644 --- a/tablib/core.py +++ b/tablib/core.py @@ -132,27 +132,31 @@ class Dataset(object): return len(self._data[0]) except KeyError, why: return 0 - + + def _package(self): + """Packages Dataset into lists of dictionaries for transmission.""" + if self.headers: + data = [dict(zip(self.headers, data_row)) for data_row in self ._data] + else: + data = [list(row) for row in self._data] + + return data + + @property def json(self): """Returns JSON representation of Dataset.""" data = [] - - if self.headers: -# for (i, header) in enumerate() - data = [dict(zip(self.headers, data_row)) for data_row in self ._data] - else: - data = self._data - return json.dumps(data) + return json.dumps(self._package()) @property def yaml(self): """Returns YAML representation of Dataset.""" - # TODO: YAML Export - pass + + return yaml.dump(self._package()) @property |
