mirror of
https://github.com/kennethreitz/tablib.git
synced 2026-06-05 23:10:17 +00:00
Documented csv import/export options from standard lib (#431)
This commit is contained in:
committed by
Hugo van Kemenade
parent
57a535f577
commit
ce7d887adc
+5
-1
@@ -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']
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user