summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2019-11-14 17:08:51 +0100
committerHugo van Kemenade <hugovk@users.noreply.github.com>2019-11-14 18:08:51 +0200
commitce7d887adc753de33812fe5eb88a1f30be396a6e (patch)
tree07d9e5a10accb9f30e7d23dedca176671f2386be
parent57a535f577379214f415a8deee5fa2ab2c5f2415 (diff)
downloadtablib-ce7d887adc753de33812fe5eb88a1f30be396a6e.tar.gz
Documented csv import/export options from standard lib (#431)
-rw-r--r--docs/conf.py6
-rw-r--r--docs/formats.rst8
-rwxr-xr-xtests/test_tablib.py6
3 files changed, 19 insertions, 1 deletions
diff --git a/docs/conf.py b/docs/conf.py
index 8df446e..2294b30 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -22,7 +22,11 @@ from pkg_resources import get_distribution
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
-extensions = ['sphinx.ext.autodoc', 'sphinx.ext.todo', 'sphinx.ext.coverage', 'sphinx.ext.viewcode']
+extensions = [
+ 'sphinx.ext.autodoc', 'sphinx.ext.todo', 'sphinx.ext.coverage',
+ 'sphinx.ext.viewcode', 'sphinx.ext.intersphinx'
+]
+intersphinx_mapping = {'python': ('https://docs.python.org/3', None)}
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
diff --git a/docs/formats.rst b/docs/formats.rst
index 489f57a..42b8cd5 100644
--- a/docs/formats.rst
+++ b/docs/formats.rst
@@ -21,6 +21,14 @@ When exporting with the ``csv`` format, the top row will contain headers, if
they have been set. Otherwise, the top row will contain the first row of the
dataset.
+When importing a CSV data source or exporting a dataset as CSV, you can pass any
+parameter supported by the :py:func:`csv.reader` and :py:func:`csv.writer`
+functions. For example::
+
+ tablib.import_set(your_data_stream, format='csv', dialect='unix')
+
+ dataset.export('csv', delimiter=' ', quotechar='|')
+
.. admonition:: Line endings
Exporting uses \\r\\n line endings by default so, make sure to include
diff --git a/tests/test_tablib.py b/tests/test_tablib.py
index 2d8798b..87482e0 100755
--- a/tests/test_tablib.py
+++ b/tests/test_tablib.py
@@ -800,6 +800,12 @@ class CSVTests(BaseTestCase):
self.assertEqual(csv, self.founders.csv)
+ def test_csv_export_options(self):
+ """Exporting support csv.writer() parameters."""
+ data.append(('1. a', '2. b', '3. c'))
+ result = data.export('csv', delimiter=' ', quotechar='|')
+ self.assertEqual(result, '|1. a| |2. b| |3. c|\r\n')
+
def test_csv_stream_export(self):
"""Verify exporting dataset object as CSV from file object."""