Generator support for petl.fromdicts()
arturponinski opened this issue · 0 comments
arturponinski commented
Minimal, reproducible code sample, a copy-pastable example if possible
import petl
data = [
{"foo":"baz"},
{"foo":"bar"}
]
table = petl.fromdicts(data)
print(petl.header(table))
print(petl.look(table))
def foo():
yield {"foo": "baz"}
yield {"foo": "bar"}
table = petl.fromdicts(foo())
print(petl.header(table))
print(petl.look(table))
Output:
('foo',)
+-------+
| foo |
+=======+
| 'baz' |
+-------+
| 'bar' |
+-------+
('foo',)
+
|
+
Problem description
When passing a generator to petl.fromdicts()
the generator is iterated only once, hence calling header()
, previewing in debug or trying to iterate the table second time, returns empty result
Version and installation information
- Value of
petl.__version__
1.7.5.dev6+dirty - Version of Python interpreter, tests on all supported versions