From 906138b138e05670913ecf233b8430d59cb6d29b Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 11 Aug 2011 00:47:23 -0400 Subject: [PATCH] a column w/ no length could work --- tablib/core.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tablib/core.py b/tablib/core.py index 166d18e..485d610 100644 --- a/tablib/core.py +++ b/tablib/core.py @@ -130,7 +130,7 @@ class Dataset(object): data.append(('John', 'Adams')) data.append(('George', 'Washington')) - data.append_col((90, 67), header='age') + data.append_col((90, 67), header='age') You can also set rows and headers upon instantiation. This is useful if dealing @@ -470,7 +470,7 @@ class Dataset(object): data.csv = 'age, first_name, last_name\\n90, John, Adams' Import assumes (for now) that headers exist. - + .. admonition:: Binary Warning :class:`Dataset.csv` uses \\r\\n line endings by default, so make @@ -478,7 +478,7 @@ class Dataset(object): with open('output.csv', 'wb') as f: f.write(data.csv)' - + If you do not do this, and you export the file on Windows, your CSV file will open in Excel with a blank line between each row. """ @@ -550,7 +550,7 @@ class Dataset(object): 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. + object at the given index. """ self._validate(row) @@ -635,9 +635,12 @@ class Dataset(object): If inserting a row, you can add :ref:`tags ` to the row you are inserting. This gives you the ability to :class:`filter ` your :class:`Dataset` later. - + """ + if col is None: + col = [] + # Callable Columns... if hasattr(col, '__call__'): col = list(map(col, self._data)) @@ -651,7 +654,7 @@ class Dataset(object): raise HeadersNeeded() # corner case - if header is set without data - elif header and self.height == 0: + elif header and self.height == 0 and len(col): raise InvalidDimensions self.headers.insert(index, header)