-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
s-raza+S20-Win
authored and
s-raza+S20-Win
committed
Oct 31, 2021
1 parent
343f0cd
commit 6e920e4
Showing
8 changed files
with
423 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
Field Processor | ||
================ | ||
|
||
A Field Processor may be used to transform the values in a row represented by | ||
a dictionary that maps ``column->value`` pairs. | ||
|
||
In *csvio* a CSV file is represented by a list of dictionaries that is | ||
populated in the ``rows`` attribute of the :py:class:`~csvio.CSVReader` or | ||
:py:class:`~csvio.CSVWriter` Classes. | ||
|
||
Once instantiated, a Field Processor Object can be used by itself to process an | ||
arbitrary dictionary that represents a row or can be passed to the constructors | ||
of :py:class:`~csvio.CSVReader` or :py:class:`~csvio.CSVWriter`. | ||
|
||
In the case where a Field Processor Object is passed to the constructor of | ||
:py:class:`~csvio.CSVReader`, it is applied to the rows of the | ||
:py:class:`~csvio.CSVReader` as soon as they are read from the CSV file. | ||
See :ref:`example code <csvreader_fp_usage>` for further details. | ||
|
||
Similarly, in the case where a Field Processor Object is passed to the | ||
constructor of :py:class:`~csvio.CSVWriter`, it is applied to the rows of the | ||
:py:class:`~csvio.CSVWriter` as soon as they are added for writing to the | ||
output CSV using the :py:func:`~csvio.CSVWriter.add_rows` method. | ||
|
||
**Standalone Example Usage** | ||
|
||
.. include:: examples/csvio.fieldprocessor.rst | ||
:start-after: start-standalone_field_processor | ||
:end-before: end-standalone_field_processor | ||
|
||
.. autoclass:: csvio.processors.field_processor.FieldProcessor | ||
:show-inheritance: | ||
:members: | ||
:inherited-members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Processor Base | ||
============== | ||
|
||
.. autoclass:: csvio.processors.processor_base.ProcessorBase | ||
:show-inheritance: | ||
:members: | ||
:inherited-members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ API Specifications | |
csvio.csvbase | ||
csvio.csvreader | ||
csvio.csvwriter | ||
csvio.fieldprocessor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
.. start-csvreader | ||
.. doctest:: | ||
|
||
>>> from csvio import CSVReader | ||
>>> reader = CSVReader("fruit_stock.csv") | ||
>>> reader.fieldnames | ||
['Supplier', 'Fruit', 'Quantity'] | ||
|
||
>>> len(reader.rows) | ||
4 | ||
|
||
>>> import json | ||
>>> print(json.dumps(reader.rows, indent=4)) | ||
[ | ||
{ | ||
"Supplier": "Big Apple", | ||
"Fruit": "Apple", | ||
"Quantity": "1" | ||
}, | ||
{ | ||
"Supplier": "Big Melons", | ||
"Fruit": "Melons", | ||
"Quantity": "2" | ||
}, | ||
{ | ||
"Supplier": "Big Mangoes", | ||
"Fruit": "Mango", | ||
"Quantity": "3" | ||
}, | ||
{ | ||
"Supplier": "Small Strawberries", | ||
"Fruit": "Strawberry", | ||
"Quantity": "4" | ||
} | ||
] | ||
|
||
*CSV file contents:* | ||
|
||
.. code-block:: bash | ||
Supplier,Fruit,Quantity | ||
Big Apple,Apple,1 | ||
Big Melons,Melons,2 | ||
Long Mangoes,Mango,3 | ||
Small Strawberries,Strawberry,4 | ||
.. end-csvreader |
Oops, something went wrong.