diff options
| author | Mike Waldner <mwaldner@gilt.com> | 2011-08-09 20:51:24 -0400 |
|---|---|---|
| committer | Mike Waldner <mwaldner@gilt.com> | 2011-08-09 20:52:09 -0400 |
| commit | 887ee2fbacc749002a1d70538c42fb93fd22b7bd (patch) | |
| tree | 22601cc461e7dd092f687235cbfa69b9ab86425f | |
| parent | c136b794a7dc1d7bcdb81a6149e0adacb5493cf8 (diff) | |
| download | tablib-887ee2fbacc749002a1d70538c42fb93fd22b7bd.tar.gz | |
Adding documentation changes for append_col
Related #21
| -rw-r--r-- | README.rst | 2 | ||||
| -rw-r--r-- | tablib/core.py | 52 |
2 files changed, 29 insertions, 25 deletions
@@ -55,7 +55,7 @@ Intelligently add new rows: :: Intelligently add new columns: :: - >>> data.append(col=(90, 67, 83), header='age') + >>> data.append_col((90, 67, 83), header='age') Slice rows: :: diff --git a/tablib/core.py b/tablib/core.py index 53f3767..72700eb 100644 --- a/tablib/core.py +++ b/tablib/core.py @@ -105,7 +105,7 @@ class Dataset(object): functionality. Usually you create a :class:`Dataset` instance in your main module, and append - rows and columns as you collect data. :: + rows as you collect data. :: data = tablib.Dataset() data.headers = ('name', 'age') @@ -113,6 +113,19 @@ class Dataset(object): for (name, age) in some_collector(): data.append((name, age)) + + Setting columns is similar. The column data length must equal the + current height of the data and headers must be set :: + + data = tablib.Dataset() + data.headers = ('first_name', 'last_name') + + data.append(('John', 'Adams')) + data.append(('George', 'Washington')) + + data.append_col((90, 67), header='age') + + You can also set rows and headers upon instantiation. This is useful if dealing with dozens or hundres of :class:`Dataset` objects. :: @@ -121,7 +134,6 @@ class Dataset(object): data = tablib.Dataset(*data, headers=headers) - :param \*args: (optional) list of rows to populate Dataset :param headers: (optional) list strings for Dataset header row @@ -518,30 +530,11 @@ class Dataset(object): def insert(self, index, row, tags=list()): """Inserts a row to the :class:`Dataset` at the given index. - Rows and columns inserted must be the correct size (height or width). + Rows inserted must be the correct size (height or width). The default behaviour is to insert the given row to the :class:`Dataset` - object at the given index. If the ``col`` parameter is given, however, - a new column will be insert to the :class:`Dataset` object instead. - - You can also insert a column of a single callable object, which will - add a new column with the return values of the callable each as an - item in the column. :: - - data.append(col=random.randint) - - See :ref:`dyncols` for an in-depth example. - - .. versionchanged:: 0.9.0 - If inserting a column, and :class:`Dataset.headers` is set, the - header attribute must be set, and will be considered the header for - that row. - - .. versionadded:: 0.9.0 - If inserting a row, you can add :ref:`tags <tags>` to the row you are inserting. - This gives you the ability to :class:`filter <Dataset.filter>` your - :class:`Dataset` later. - """ + object at the given index. + """ self._validate(row) self._data.insert(index, Row(row, tags=tags)) @@ -615,6 +608,17 @@ class Dataset(object): that row. See :ref:`dyncols` for an in-depth example. + + .. versionchanged:: 0.9.0 + If inserting a column, and :class:`Dataset.headers` is set, the + header attribute must be set, and will be considered the header for + that row. + + .. versionadded:: 0.9.0 + If inserting a row, you can add :ref:`tags <tags>` to the row you are inserting. + This gives you the ability to :class:`filter <Dataset.filter>` your + :class:`Dataset` later. + """ # Callable Columns... |
