Processor Base

class csvio.processors.processor_base.ProcessorBase(handle: str)

Bases: object

Processor Base Class

add_processor(fieldname: str, func_: Union[List[Callable[[str], Any]], Callable[[str], Any]], handle: Optional[str] = None) None

Add a processor to process fields in a row.

Parameters
  • fieldname (required) – Name of the field upon which the processor should be executed.

  • func (required) – Field processor function reference or a list of such function references. All function references added with the same handle will be executed for the field, to transform its value in the same order as they are added.

  • handle (optional) – Processor reference handle to which the processor will be added. If not provided, the handle of the current object will be used.

Returns

None

See example code for using with CSVReader

See example code for using with CSVWriter

process_row(row: Dict[str, Any], processor_handle: Optional[Union[Type[csvio.processors.processor_base.ProcessorBase], str]] = None) Dict[str, Any]

Process a single row

Parameters
  • row (required) – A single dictionary of fieldname->value pairs representing a single row

  • processor_handle (optional) – A processor handle or an object that references the processor functions to apply and transform the row values. The processor functions of the current object are used if this argument is not provided.

Returns

A dictionary representing a processed CSV row

process_rows(rows: List[Dict[str, Any]], processor_handle: Optional[str] = None) List[Dict[str, Any]]

Process a list of rows

Parameters
  • row (required) – A list of dictionaries of fieldname->value pairs representing a list of rows

  • processor_handle (optional) – A processor handle or an object that references the processor functions to apply and transform the row values. The processor functions of the current object are used if this argument is not provided.

Returns

A list of dictionaries representing processed CSV rows