Skip to content

Commit d8107ca

Browse files
authored
Improve sample codes about json.dumps usage (#51)
1 parent 3b3639d commit d8107ca

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Diff for: README.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Here's the sample code:
136136
>>> from pyexcel_xlsx import get_data
137137
>>> data = get_data("your_file.xlsx")
138138
>>> import json
139-
>>> print(json.dumps(data))
139+
>>> print(json.dumps(data, default=str))
140140
{"Sheet 1": [[1, 2, 3], [4, 5, 6]], "Sheet 2": [["row 1", "row 2", "row 3"]]}
141141
142142
@@ -171,7 +171,7 @@ Continue from previous example:
171171
>>> # In reality, you might deal with xlsx file upload
172172
>>> # where you will read from requests.FILES['YOUR_XLSX_FILE']
173173
>>> data = get_data(io)
174-
>>> print(json.dumps(data))
174+
>>> print(json.dumps(data, default=str))
175175
{"Sheet 1": [[1, 2, 3], [4, 5, 6]], "Sheet 2": [[7, 8, 9], [10, 11, 12]]}
176176
177177
@@ -202,15 +202,15 @@ And let's pretend to read partial data:
202202
.. code-block:: python
203203
204204
>>> partial_data = get_data("huge_file.xlsx", start_row=2, row_limit=3)
205-
>>> print(json.dumps(partial_data))
205+
>>> print(json.dumps(partial_data, default=str))
206206
{"huge": [[3, 23, 33], [4, 24, 34], [5, 25, 35]]}
207207
208208
And you could as well do the same for columns:
209209

210210
.. code-block:: python
211211
212212
>>> partial_data = get_data("huge_file.xlsx", start_column=1, column_limit=2)
213-
>>> print(json.dumps(partial_data))
213+
>>> print(json.dumps(partial_data, default=str))
214214
{"huge": [[21, 31], [22, 32], [23, 33], [24, 34], [25, 35], [26, 36]]}
215215
216216
Obvious, you could do both at the same time:
@@ -220,7 +220,7 @@ Obvious, you could do both at the same time:
220220
>>> partial_data = get_data("huge_file.xlsx",
221221
... start_row=2, row_limit=3,
222222
... start_column=1, column_limit=2)
223-
>>> print(json.dumps(partial_data))
223+
>>> print(json.dumps(partial_data, default=str))
224224
{"huge": [[23, 33], [24, 34], [25, 35]]}
225225
226226
.. testcode::

0 commit comments

Comments
 (0)