Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples of valid and invalid usage of generator as table container #642

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,23 @@ So, for example, a list of lists is a valid table container::

>>> table = [['foo', 'bar'], ['a', 1], ['b', 2]]

Please keep in mind that using batched data generators is forbidden:

>>> from itertools import batched
>>> def invalid_container_generator():
>>> for data_rows_batch in batched([['foo', 'bar'], ['a', 1], ['b', 2], ['c', 3]], 2):
>>> yield data_rows_batch
>>>
>>> table = invalid_container_generator()

Generator used as table container should yield single data row at a time:

>>> def valid_container_generator():
>>> for data_row in [['foo', 'bar'], ['a', 1], ['b', 2], ['c', 3]]:
>>> yield data_row
>>>
>>> table = valid_container_generator()

Note that an object returned by the :func:`csv.reader` function from the
standard Python :mod:`csv` module is a table iterator and **not** a table
container, because it can only be iterated over once. However, it is
Expand Down