Skip to content

Commit

Permalink
Improve sample codes about json.dumps usage (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
peter279k authored Nov 10, 2024
1 parent 3b3639d commit d8107ca
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Here's the sample code:
>>> from pyexcel_xlsx import get_data
>>> data = get_data("your_file.xlsx")
>>> import json
>>> print(json.dumps(data))
>>> print(json.dumps(data, default=str))
{"Sheet 1": [[1, 2, 3], [4, 5, 6]], "Sheet 2": [["row 1", "row 2", "row 3"]]}
Expand Down Expand Up @@ -171,7 +171,7 @@ Continue from previous example:
>>> # In reality, you might deal with xlsx file upload
>>> # where you will read from requests.FILES['YOUR_XLSX_FILE']
>>> data = get_data(io)
>>> print(json.dumps(data))
>>> print(json.dumps(data, default=str))
{"Sheet 1": [[1, 2, 3], [4, 5, 6]], "Sheet 2": [[7, 8, 9], [10, 11, 12]]}
Expand Down Expand Up @@ -202,15 +202,15 @@ And let's pretend to read partial data:
.. code-block:: python
>>> partial_data = get_data("huge_file.xlsx", start_row=2, row_limit=3)
>>> print(json.dumps(partial_data))
>>> print(json.dumps(partial_data, default=str))
{"huge": [[3, 23, 33], [4, 24, 34], [5, 25, 35]]}
And you could as well do the same for columns:

.. code-block:: python
>>> partial_data = get_data("huge_file.xlsx", start_column=1, column_limit=2)
>>> print(json.dumps(partial_data))
>>> print(json.dumps(partial_data, default=str))
{"huge": [[21, 31], [22, 32], [23, 33], [24, 34], [25, 35], [26, 36]]}
Obvious, you could do both at the same time:
Expand All @@ -220,7 +220,7 @@ Obvious, you could do both at the same time:
>>> partial_data = get_data("huge_file.xlsx",
... start_row=2, row_limit=3,
... start_column=1, column_limit=2)
>>> print(json.dumps(partial_data))
>>> print(json.dumps(partial_data, default=str))
{"huge": [[23, 33], [24, 34], [25, 35]]}
.. testcode::
Expand Down

0 comments on commit d8107ca

Please sign in to comment.