diff options
| author | DougHudgeon <doug@mybusinessautomated.com> | 2018-06-26 10:33:21 +1000 |
|---|---|---|
| committer | DougHudgeon <doug@mybusinessautomated.com> | 2018-06-26 10:33:21 +1000 |
| commit | f812c29275c7f47b08f8f1b962625545ec4e22ad (patch) | |
| tree | f06b62a7978d15a54ab3ee7f016156afd74c0bc2 | |
| parent | 4c5d0b1a457b55c943fbff888459ad224c8a5bcd (diff) | |
| download | tablib-f812c29275c7f47b08f8f1b962625545ec4e22ad.tar.gz | |
Add instructions for handling csv line endings in Windows in Python 3
| -rw-r--r-- | tablib/core.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/tablib/core.py b/tablib/core.py index 8c49f2e..e0d61f0 100644 --- a/tablib/core.py +++ b/tablib/core.py @@ -526,9 +526,9 @@ class Dataset(object): Import assumes (for now) that headers exist. - .. admonition:: Binary Warning + .. admonition:: Binary Warning for Python 2 - :class:`Dataset.csv` uses \\r\\n line endings by default, so make + :class:`Dataset.csv` uses \\r\\n line endings by default so, in Python 2, make sure to write in binary mode:: with open('output.csv', 'wb') as f: @@ -536,6 +536,18 @@ class Dataset(object): 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. + + .. admonition:: Line endings for Python 3 + + :class:`Dataset.csv` uses \\r\\n line endings by default so, in Python 3, make + sure to include newline='' otherwise you will get a blank line between each row + when you open the file in Excel:: + + with open('output.csv', 'w', newline='') 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. """ pass |
