bw_simapro_csv.csv_reader

Attributes

CONTROL_CHARACTERS

UNDEFINED

WARNING_CHARS

Classes

BeKindRewind

CSV reader which acts as a line by line iterator but which allows for one step backwards.

Functions

clean(→ str)

Strip string, fix encoding, and remove undefined or control characters

Module Contents

class bw_simapro_csv.csv_reader.BeKindRewind(data_iterable: collections.abc.Iterator, clean_elements: bool = True, offset: int = 0)[source]

Bases: collections.abc.Iterator

CSV reader which acts as a line by line iterator but which allows for one step backwards.

Needed because the file we are consuming will sometimes indicate that a logical block is finished by using the control word End, but other times won’t. In that case, our iterator is already in a new block. To make it simple to pass the iterator to the next function consuming the new block, we rewind it one line.

Internally this is implemented by caching the last line read, and using itertools.chain when needed to prepend the cached line to the iterator.

Parameters:
  • data_iterable (collections.abc.Iterator) – Iterator which returns lists of strings.

  • clean_elements (bool, optional)

  • line (Do [clean(elem) for elem in line] when returning a new)

rewind() None[source]

Rewinds the iterator by one step, retrieving the element that was just returned by the previous call to __next__.

clean_elements = True[source]
current = None[source]
data_iterable[source]
line_no = 1[source]
bw_simapro_csv.csv_reader.clean(s: str) str[source]

Strip string, fix encoding, and remove undefined or control characters

bw_simapro_csv.csv_reader.CONTROL_CHARACTERS[source]
bw_simapro_csv.csv_reader.UNDEFINED[source]
bw_simapro_csv.csv_reader.WARNING_CHARS = 'À˜â¿'[source]