mirror of
https://github.com/kennethreitz/tablib.git
synced 2026-06-05 06:56:13 +00:00
correct example (#276)
map() is a function in python2, and iterator in python3+; In any case - map is inefficient compared to either comprehensions (most efficient), or simple loops (close second). SInce in this case, data.append() returns nothing, use a simple look. It is clearer, more efficient, and works with both python2 and python3
This commit is contained in:
+3
-1
@@ -27,7 +27,9 @@ Tablib is an :ref:`MIT Licensed <mit>` format-agnostic tabular dataset library,
|
|||||||
::
|
::
|
||||||
|
|
||||||
>>> data = tablib.Dataset(headers=['First Name', 'Last Name', 'Age'])
|
>>> data = tablib.Dataset(headers=['First Name', 'Last Name', 'Age'])
|
||||||
>>> map(data.append, [('Kenneth', 'Reitz', 22), ('Bessie', 'Monke', 21)])
|
>>> for i in [('Kenneth', 'Reitz', 22), ('Bessie', 'Monke', 21)]:
|
||||||
|
... data.append(i)
|
||||||
|
|
||||||
|
|
||||||
>>> print data.json
|
>>> print data.json
|
||||||
[{"Last Name": "Reitz", "First Name": "Kenneth", "Age": 22}, {"Last Name": "Monke", "First Name": "Bessie", "Age": 21}]
|
[{"Last Name": "Reitz", "First Name": "Kenneth", "Age": 22}, {"Last Name": "Monke", "First Name": "Bessie", "Age": 21}]
|
||||||
|
|||||||
Reference in New Issue
Block a user